dropRepeated
Only pass on those elements that are distinct from the previous element.
Signature
Source.dropRepeatedSource.dropRepeated Flow.dropRepeatedFlow.dropRepeated Source.dropRepeatedSource.dropRepeated Flow.dropRepeatedFlow.dropRepeated
Description
Only pass on those elements that are distinct from the previous element.
By default elements are compared using equality. An overload accepting a predicate p can be used instead, in which case an element is dropped when p returns true for the previous element and the current element.
Example
For example, given a Source of numbers, we just want to pass distinct numbers downstream:
- Scala
-
source
Source(List(1, 2, 2, 3, 3, 1, 4)) .dropRepeated() .runForeach(println) // prints: // 1 // 2 // 3 // 1 // 4 - Java
-
source
Source.from(List.of(1, 2, 2, 3, 3, 1, 4)) .dropRepeated() .runForeach(System.out::println, system); // prints: // 1 // 2 // 3 // 1 // 4
Reactive Streams semantics
emits when the element is distinct from the previous element
backpressures when the element is distinct from the previous element and downstream backpressures
completes when upstream completes