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
sourceval droppedWhileNegative = Source(-3 to 3).dropWhile(_ < 0)

droppedWhileNegative.runForeach(println)
// 0
// 1
// 2
// 3
Java
sourceSource<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

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.