Example for mapConcat (#28243)

* Example for mapConcat
This commit is contained in:
Christopher Batey 2019-11-26 18:39:42 +00:00 committed by Arnout Engelen
parent a9d545bf2b
commit 8027f2123b
3 changed files with 82 additions and 0 deletions

View file

@ -0,0 +1,33 @@
/*
* Copyright (C) 2019 Lightbend Inc. <https://www.lightbend.com>
*/
package docs.stream.operators.sourceorflow
import akka.stream.scaladsl.Source
import scala.concurrent.ExecutionContext
object MapConcat {
def mapConcat(): Unit = {
import akka.actor.ActorSystem
implicit val system: ActorSystem = ActorSystem()
implicit val ec: ExecutionContext = system.dispatcher
//#map-concat
def duplicate(i: Int): List[Int] = List(i, i)
Source(1 to 3).mapConcat(i => duplicate(i)).runForeach(println)
// prints:
// 1
// 1
// 2
// 2
// 3
//#map-concat
}
}