Skip to Content
Scala Reactive Programming
book

Scala Reactive Programming

by Rambabu Posa
February 2018
Intermediate to advanced
552 pages
13h 46m
English
Packt Publishing
Content preview from Scala Reactive Programming

Connecting a Source to a Flow to a Sink

Now, we will try to connect all three major components of the Akka Streams API:

val numbersSource = Source(1 to 10) 
val sampleSink = Sink.foreach(println) 
val numberFlow = Flow[Int].map(num => num+1) 

Create all three components to work on numbers. We can use Source's via function to connect a Source to Flow and Flow's to function to connect a Flow to Sink.

val numberRunnableGraph = numbersSource.via(numberFlow).to(sampleSink)

This is a fully connected RunnableGraph with all three components. When we run this code, it also does give any output.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Scala Programming Projects

Scala Programming Projects

Mikael Valot, Nicolas Jorand
Learning Scala

Learning Scala

Jason Swartz
Functional Programming in Scala

Functional Programming in Scala

Runar Bjarnason, Paul Chiusano

Publisher Resources

ISBN: 9781787288645Supplemental Content