Skip to content

Instantly share code, notes, and snippets.

@dakatsuka
Created September 13, 2016 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dakatsuka/ae8f55de6804dc4d219ff6e87363f51d to your computer and use it in GitHub Desktop.
Save dakatsuka/ae8f55de6804dc4d219ff6e87363f51d to your computer and use it in GitHub Desktop.
implicit val system = ActorSystem()
implicit val executor = system.dispatcher
implicit val materializer = ActorMaterializer()
val source: Source[Int, NotUsed] = Source(1 to 10)
val flow1: Flow[Int, Int, NotUsed] = Flow[Int].map(_ * 10)
val flow2: Flow[Int, Int, NotUsed] = Flow[Int].filter(_ % 3 == 0)
val flow3: Flow[Int, Int, NotUsed] = Flow[Int].statefulMapConcat { () =>
var sequence = 0
i =>
sequence = sequence + i
List(sequence)
}
source.via(flow1).via(flow2).via(flow3).runForeach(println)
// 30
// 90
// 180
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment