I have just started learning RxJava and thinking reactive. I have found some article (7 tips) that says subjects should only be used as a last resort or the first implementation, and I have been thinking.. As of now I have one PublishSubject
PublishSubject.create()
.scan(0, (a, b) -> a + 1).subscribe(replaySubject)
It is incrementing the value by 1 every time, and is subscribed by replaySubject
ReplaySubject.create();
That just prints the value. So at start I have 0, then on every PublishSubject.onNext I am incrementing the value, so I got 1, 2 etc. Because its replaySubject I am getting the whole chain.
However I have been thinking whether or not this may be done without subjects? I have been reading the RxJava Wiki and the operators, but I can't figure out any way this could be done.
Update
So the pseudo code I am trying to archieve is somehow to have one observable that starts with 1
Observable.just(1)
Now I do have on click listener
OnClick{ }
And every time I click on some button I want to see all previous numbers + 1, so 1 then 1, 2 next 1,2,3 etc.
I have been trying with ConnectableObservator.replay however this does not succeeded at all. And inside listener I jave been trying to first add scan on my Observable to increase value and then subscribe so I can print it. But this does not work either. Damn I think i'm in a black corner and misunderstood the idea of observables...
PublishSubject? - zsxwingobservable.scan(0, (a, b) -> a + 1)dost not work? - zsxwingObservable.just(0)and a button click event, now I have one subscriber that subscribes to myObservableand prints its value. So it prints 0. Now I on every button click I want to increment that value and send it to all subscribers, I might not understand the whole idea yet - user3274539