Is there a possibility to emit item that meets condition in takeUntil
operator?
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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With