Example for intersperse (#28343)

This commit is contained in:
Christopher Batey 2019-12-11 14:39:41 +00:00 committed by Johan Andrén
parent 1e67d9221e
commit 17533f077c
4 changed files with 70 additions and 9 deletions

View file

@ -0,0 +1,22 @@
/*
* Copyright (C) 2019 Lightbend Inc. <https://www.lightbend.com>
*/
package docs.stream.operators.sourceorflow
import akka.stream.scaladsl.Sink
import akka.stream.scaladsl.Source
object Intersperse extends App {
import akka.actor.ActorSystem
implicit val system: ActorSystem = ActorSystem()
//#intersperse
Source(1 to 4).map(_.toString).intersperse("[", ", ", "]").runWith(Sink.foreach(print))
// prints
// [1, 2, 3, 4]
//#intersperse
system.terminate()
}