Is there a possibility to emit item that meets condition in takeUntil
operator?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Mmmm not sure if I understand your question. Something like this?
@Test
public void tesTakeUntil() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
Observable.from(numbers)
.takeUntil(number -> number > 3)
.subscribe(System.out::println);
}
it will print
1
2
3
4
You can see more examples of Take here https://github.com/politrons/reactive/blob/master/src/test/java/rx/observables/filtering/ObservableTake.java
回答2:
With this solution, the predicate only has to be called once.
final String stop = "c";
Observable.just("a", "b", "c", "d")
.takeUntil(item -> item.equals(stop))
.lastElement()
.subscribe(System.out::println);
Output:
c
回答3:
final String stop = "c";
Observable.just("a", "b", "c", "d")
.filter(item -> !item.equals(stop))
.takeUntil(item -> item.equals(stop))
.subscribe(System.out::println);
Output:
c