zipLatest

Combines elements from each of multiple sources into tuples Pair and passes the tuples pairs downstream, picking always the latest element of each.

Fan-in operators

Signature

Source.zipLatestSource.zipLatest Flow.zipLatestFlow.zipLatest

Description

Combines elements from each of multiple sources into tuples Pair and passes the tuples pairs downstream, picking always the latest element of each.

No element is emitted until at least one element from each Source becomes available.

Example

Scala
sourceval numbers = Source(1 :: 2 :: Nil)
val letters = Source("a" :: "b" :: Nil)

numbers.zipLatest(letters).runForeach(println)
// this will print
// (1,a)
// (2,a)
// (2,b)
// NOTE : The output is not always deterministic and also depends on order of elements flowing from the streams.
// Sometimes the output could also be :
// (1, a)
// (1, b)
// (2, b)
Java
source
Source<Integer, NotUsed> numbers = Source.from(Arrays.asList(1, 2)); Source<String, NotUsed> letters = Source.from(Arrays.asList("a", "b")); numbers.zipLatest(letters).runForeach(System.out::println, system); // this will print // Pair(1,a) // Pair(2,a) // Pair(2,b) // // NOTE : The output is not always deterministic and also depends on order of elements flowing // from the streams. // Sometimes the output could also be : // Pair(1, a) // Pair(1, b) // Pair(2, b)

Reactive Streams semantics

emits when all of the inputs have at least an element available, and then each time an element becomes available on either of the inputs

backpressures when downstream backpressures

completes when any upstream completes

cancels when downstream cancels

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.