A Flow is the transformation stage in an Akka Streams pipeline. It accepts elements from an upstream Source, transforms them, and passes the results to a downstream Sink. section 10.1.1 section 16.0
A linear stream combines three stages:
- Source produces elements. section 10.1.2
- Flow transforms elements between the producer and consumer. section 10.1.2
- Sink consumes elements, such as by storing them in a database. section 10.1.2
Filtering a finite stream
A processor can retain only even integers: `val processor: Flow[Int, Int, NotUsed] = Flow[Int].filter(_ % 2 == 0)`. Connect it with `producer.via(processor).toMat(consumer)(Keep.right)` and run the resulting blueprint. With a source containing `List(1, 2, 3)` and a sink writing to a fake database, only `2` is stored. section 10.1.2 section 10.1.4 section 10.1.7
The type `Flow[Int, Int, NotUsed]` declares integer input, integer output, and an unused materialized value. Flows can serve finite or infinite streams; the API remains the same. section 10.1.2 section 10.1.4
val processor: Flow[Int, Int, NotUsed] = Flow[Int].filter(_ % 2 == 0)
The typed filtering processor makes the Flow’s input, output, and transformation explicit. section 10.1.4
