zipAll

Combines all elements from each of multiple sources into tuples Pair and passes the tuples pairs downstream.

Fan-in operators

Signature

def zipAll[U, A >: Out](that: Graph[SourceShape[U], _], thisElem: A, thatElem: U): Repr[(A, U)]
def zipAllMat[U, Mat2, Mat3, A >: Out](that: Graph[SourceShape[U], Mat2], thisElem: A, thatElem: U)(matF: (Mat, Mat2) => Mat3): ReprMat[(A, U), Mat3]

Description

Combines all elements from each of multiple sources into tuples Pair and passes the tuples pairs downstream.

Reactive Streams semantics

emits at first emits when both inputs emit, and then as long as any input emits (coupled to the default value of the completed input).

backpressures when downstream backpressures

completes when all upstream completes

Example

Scala
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
import akka.stream.javadsl.Source;
import akka.stream.javadsl.Sink;
import java.util.Arrays;

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).runWith(Sink.foreach(System.out::print), system);
// this will print ('apple', 'A'), ('orange', 'O'), ('banana', 'B')
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.