dropWhile

Drop elements as long as a predicate function return true for the element

Simple operators

Signature

Source.dropWhileSource.dropWhile Flow.dropWhileFlow.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
val droppedWhileNegative = Source(-3 to 3).dropWhile(_ < 0)

droppedWhileNegative.runForeach(println)
// 0
// 1
// 2
// 3
Java
Source<Integer, NotUsed> droppedWhileNegative =
    Source.from(Arrays.asList(-3, -2, -1, 0, 1, 2, 3, -1)).dropWhile(integer -> integer < 0);

droppedWhileNegative.runWith(Sink.foreach(System.out::print), 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

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.