Search code examples
rx-java2reactivex

How to emit a boolean only when the previous one is different using Rx Operator?


I have a boolean Observable. I want to emit value(another boolean) only if the current boolean value is different from preview.

booleanObservable

            // which operator here

            .subscribe(new Consumer<Boolean>() {
                @Override
                public void accept(Boolean emittedBoolean) throws Exception {
                    // do something with emittedBoolean
                }
            });

Solution

  • you should use this : distinctUntilChanged()