Adding example for collection operator (#29716)
* Adding example for collection operator * Modifying example * Add parenthesises to side effect only method Co-authored-by: Johan Andrén <johan@markatta.com>
This commit is contained in:
parent
4620c64dc6
commit
0e0680bd82
2 changed files with 30 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.stream.operators.sink
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.stream.scaladsl.{ Sink, Source }
|
||||
|
||||
import scala.concurrent.{ ExecutionContextExecutor, Future }
|
||||
|
||||
object Collection {
|
||||
implicit val system: ActorSystem = ???
|
||||
implicit val ec: ExecutionContextExecutor = system.dispatcher
|
||||
def collectionExample(): Unit = {
|
||||
//#collection
|
||||
val source = Source(1 to 5)
|
||||
val result: Future[List[Int]] = source.runWith(Sink.collection[Int, List[Int]])
|
||||
result.foreach(println)
|
||||
//List(1, 2, 3, 4, 5)
|
||||
//#collection
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue