zip
Combines elements from each of multiple sources into tuples Pair and passes the tuples pairs downstream.
Signature
Source.zip
Source.zip
Flow.zip
Flow.zip
Description
Combines elements from each of multiple sources into tuples Pair and passes the tuples pairs downstream.
See also:
Examples
- Scala
-
source
import akka.stream.scaladsl.Source import akka.stream.scaladsl.Sink val sourceFruits = Source(List("apple", "orange", "banana")) val sourceFirstLetters = Source(List("A", "O", "B")) sourceFruits.zip(sourceFirstLetters).runWith(Sink.foreach(println)) // this will print ('apple', 'A'), ('orange', 'O'), ('banana', 'B')
- Java
-
source
import akka.stream.javadsl.Keep; import akka.stream.javadsl.Source; import akka.stream.javadsl.Sink; import java.util.*; Source<String, NotUsed> sourceFruits = Source.from(Arrays.asList("apple", "orange", "banana")); Source<String, NotUsed> sourceFirstLetters = Source.from(Arrays.asList("A", "O", "B")); sourceFruits.zip(sourceFirstLetters).runForeach(System.out::println, system); // this will print ('apple', 'A'), ('orange', 'O'), ('banana', 'B')
Reactive Streams semantics
emits when both of the inputs have an element available
backpressures both upstreams when downstream backpressures but also on an upstream that has emitted an element until the other upstream has emitted an element
completes when either upstream completes