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 org.apache.pekko import pekko.stream.scaladsl.Source import pekko.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 org.apache.pekko.stream.javadsl.Keep; import org.apache.pekko.stream.javadsl.Source; import org.apache.pekko.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
1.1.2+29-e21fa9eb*