如何使用 Rx 运算符仅在前一个不同时才发出布尔值?
How to emit a boolean only when the previous one is different using Rx Operator?
我有一个布尔 Observable。我只想在当前布尔值与预览不同时发出值(另一个布尔值)。
booleanObservable
// which operator here
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean emittedBoolean) throws Exception {
// do something with emittedBoolean
}
});
你应该使用这个:distinctUntilChanged()
我有一个布尔 Observable。我只想在当前布尔值与预览不同时发出值(另一个布尔值)。
booleanObservable
// which operator here
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean emittedBoolean) throws Exception {
// do something with emittedBoolean
}
});
你应该使用这个:distinctUntilChanged()