These are chat archives for ReactiveX/RxJava

10th
Dec 2016
Ann
@WeiWW
Dec 10 2016 01:25
Hello!
Dorus
@Dorus
Dec 10 2016 01:38
@Cir0X Instead of emitting all conditions on 1 stream, you should have 3 streams and combine these streams. Could be done with a number of operators, my gut feeling is combineLatest(conditionA, conditionB, conditionC) would work best. You also seem to be doing a.value everywhere, you could add in a .map(a -> a.value) so you can look at the value directly later.
Next there are a few options to act on this stream. I wouldn't filter if you want to do all operations on the same stream, as filter takes out elements and you wont be able to act on them after that. Instead you can make a large do or subscribe block where you test all conditions one by one, or you can simply subscribe to the condition stream multiple times, and filter out the correct elements. Myself i would then do .filter((arr) -> !arr[0]).filter((arr) -> !arr[1]).filter((arr) -> !arr[2]) instead of !arr[0] && !arr[1] && !arr[2].
If you subscribe multiple times, that means the source stream will also run multiple times. Depending on the source, you might want to multicast instead. You can do that with share().
Another interesting solution would be to use .publish(selector), like this:
getCondition().publish(_conditions -> Observable.merge(
    _conditions.filter(a -> a[0] == 0).filter(a -> a[1] == 0).filter(a -> a[2] == 0).do(() -> sometihngA()),
    _conditions.filter(a -> a[0] == 0).filter(a -> a[1] == 1).filter(a -> a[2] == 1).do(() -> sometihngB()),
    _conditions.filter(a -> a[0] == 0).filter(a -> a[1] == 1).filter(a -> a[2] == 0).do(() -> sometihngC())
  )).subscribe();
Mmm looking back i think the && style would be just as good :)