Docs: Reduce operator (#29641)
Co-authored-by: Arnout Engelen <github@bzzt.net>
This commit is contained in:
parent
4d00f9a8e8
commit
a12867b8b1
3 changed files with 44 additions and 1 deletions
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (C) 2009-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 Reduce {
|
||||
implicit val system: ActorSystem = ???
|
||||
implicit val ec: ExecutionContextExecutor = system.dispatcher
|
||||
def reduceExample: Future[Unit] = {
|
||||
//#reduceExample
|
||||
val source = Source(1 to 100).reduce((acc, element) => acc + element)
|
||||
val result: Future[Int] = source.runWith(Sink.head)
|
||||
result.map(println)
|
||||
//5050
|
||||
//#reduceExample
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue