add examples for scan operator #25468

This commit is contained in:
airt 2019-01-04 22:08:54 +08:00 committed by Johan Andrén
parent a8a443abec
commit e124d11995
3 changed files with 39 additions and 0 deletions

View file

@ -52,4 +52,23 @@ object SourceOrFlow {
//#conflateWithSeed
}
def scanExample(): Unit = {
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
implicit val system: ActorSystem = ActorSystem()
implicit val materializer: ActorMaterializer = ActorMaterializer()
//#scan
val source = Source(1 to 5)
source.scan(0)((acc, x) acc + x).runForeach(println)
// 0 (= 0)
// 1 (= 0 + 1)
// 3 (= 0 + 1 + 2)
// 6 (= 0 + 1 + 2 + 3)
// 10 (= 0 + 1 + 2 + 3 + 4)
// 15 (= 0 + 1 + 2 + 3 + 4 + 5)
//#scan
}
}