dropWhile
Drop elements as long as a predicate function return true for the element
Signature
Source.dropWhile
Source.dropWhile
Flow.dropWhile
Flow.dropWhile
Description
Drop elements as long as a predicate function return true for the element
Example
Given a Source
of ordered numbers we can drop all the negative ones with the dropWhile
operator. Mind that after the first non negative number is encountered, all the consecutive elements will be emitted despite the predicate provided.
- Scala
-
source
val droppedWhileNegative = Source(-3 to 3).dropWhile(_ < 0) droppedWhileNegative.runForeach(println) // 0 // 1 // 2 // 3
- Java
-
source
Source<Integer, NotUsed> droppedWhileNegative = Source.from(Arrays.asList(-3, -2, -1, 0, 1, 2, 3, -1)).dropWhile(integer -> integer < 0); droppedWhileNegative.runForeach(System.out::println, system); // 1 // 2 // 3 // -1
Reactive Streams semantics
emits when the predicate returned false and for all following stream elements
backpressures predicate returned false and downstream backpressures
completes when upstream completes
1.1.2+24-bcd44ee3*