map

Transform each element in the stream by calling a mapping function with it and passing the returned value downstream.

Simple operators

Signature

Source.mapSource.map Flow.mapFlow.map

Description

Transform each element in the stream by calling a mapping function with it and passing the returned value downstream.

Examples

Scala
sourceimport org.apache.pekko
import pekko.NotUsed
import pekko.stream.scaladsl._

val source: Source[Int, NotUsed] = Source(1 to 10)
val mapped: Source[String, NotUsed] = source.map(elem => elem.toString)

Reactive Streams semantics

emits when the mapping function returns an element

backpressures when downstream backpressures

completes when upstream completes