zipWithIndex
Zips elements of current flow with its indices.
Fan-in operators
Signature
def zipWithIndex: Repr[(Out, Long)]
Description
Zips elements of current flow with its indices.
emits upstream emits an element and is paired with their index
backpressures when downstream backpressures
completes when upstream completes
Example
- Scala
-
sourceimport akka.stream.scaladsl.Source
import akka.stream.scaladsl.Sink
Source(List("apple", "orange", "banana")).zipWithIndex.runWith(Sink.foreach(println))
// this will print ('apple', 0), ('orange', 1), ('banana', 2)
- Java
-
sourceimport akka.stream.javadsl.Source;
import akka.stream.javadsl.Sink;
import java.util.Arrays;
Source.from(Arrays.asList("apple", "orange", "banana"))
.zipWithIndex()
.runWith(Sink.foreach(System.out::print), materializer);
// this will print ('apple', 0), ('orange', 1), ('banana', 2)
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.