2014-12-08 17:29:40 +01:00
|
|
|
package docs.stream.cookbook
|
|
|
|
|
|
2016-01-20 10:00:37 +02:00
|
|
|
import akka.NotUsed
|
2014-12-08 17:29:40 +01:00
|
|
|
import akka.stream.scaladsl.{ Sink, Source }
|
|
|
|
|
|
|
|
|
|
import scala.collection.immutable
|
|
|
|
|
import scala.concurrent.Await
|
|
|
|
|
import scala.concurrent.duration._
|
|
|
|
|
|
|
|
|
|
class RecipeFlattenSeq extends RecipeSpec {
|
|
|
|
|
|
|
|
|
|
"Recipe for flatteing a stream of seqs" must {
|
|
|
|
|
|
|
|
|
|
"work" in {
|
|
|
|
|
|
|
|
|
|
val someDataSource = Source(List(List("1"), List("2"), List("3", "4", "5"), List("6", "7")))
|
|
|
|
|
|
|
|
|
|
//#flattening-seqs
|
2016-01-20 10:00:37 +02:00
|
|
|
val myData: Source[List[Message], NotUsed] = someDataSource
|
|
|
|
|
val flattened: Source[Message, NotUsed] = myData.mapConcat(identity)
|
2014-12-08 17:29:40 +01:00
|
|
|
//#flattening-seqs
|
|
|
|
|
|
2016-02-12 01:36:21 +08:00
|
|
|
Await.result(flattened.limit(8).runWith(Sink.seq), 3.seconds) should be(List("1", "2", "3", "4", "5", "6", "7"))
|
2014-12-08 17:29:40 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|