Reputation: 9301
Is there a way to create observables based on some conditions?
For example if I have Observable.just(1, 2, 3, ..., n)
and if next emitted item is 1, then doSomethingA
, if 5 then doSomethignB
otherwise doWithEverythingElse
.
Or am I asking too much? :)
Upvotes: 0
Views: 461
Reputation: 12087
Use an if
statement in doOnNext
:
observable.doOnNext(i ->
if (i==1)
doSomethingA();
else if (i==5)
doSomethingB();
else
doWithEverythingElse());
Upvotes: 2