zip

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

Fan-in operators

Signature

Source.zipSource.zip Flow.zipFlow.zip

Description

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

See also:

Examples

Scala
sourceimport 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
sourceimport 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

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.