0

I am trying to generate an Observable through using and looking at last 4 data from another Observable. I am not able to figure it out yet.

I have a data class A(val b: B) . Then I have the following obeserver

// My value storer. That keeps on getting filled up
val rep = ReplayRelay.createWithSize<A>(4)


// Now I need to generate another Observable based on `rep` which looks at `b` for the last 4 sets of data anytime `rep` has new data

`fun generateObservable() : Observable<A>`

What I want do

  1. is observe rep
  2. Takes the last 4 items in rep
  3. Check if val b: B and then send back one A, I do not want this to end, it should continuously keep on looking at rep for every item it adds.
  4. Return another observer around 3

Example -> Stream 1, 2, 3, 4, 5, 6

rep stream -> (looks at 1, 2, 3,4), (looks at 2,3,4,5), (looks at 3,4,5,6)

Thanks all!

I looked into scan which only looks at the last 2, looked into take and takeLast that ends the Observable. buffer doesnt work as I need to look at the last 4 and not skip. I looked at buffer but I cant provide negative values.

Progman
  • 16,827
  • 6
  • 33
  • 48
  • Sounds like you need [`buffer(4, 1)`](http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Observable.html#buffer-int-int-). – akarnokd Jan 29 '23 at 11:32
  • Please [edit] your question to include a detailed marble-diagram of the values in your observables and how they should generate/read the values based on time and these observables. – Progman Jan 29 '23 at 12:39

0 Answers0