Skip to content

Commit 6e2bab9

Browse files
committed
[hello-akka-streams] factorial
1 parent 24fca40 commit 6e2bab9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

hello-akka-stream/src/main/scala/example/Hello.scala

+7-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ import java.nio.file.Paths
1212
object Hello extends App {
1313
implicit val system = ActorSystem("QuickStart")
1414

15-
val source: Source[Int, NotUsed] = Source(1 to 100)
16-
val done: Future[Done] = source.runForeach(i => println(i))
15+
val factorials = Source(1 to 100).scan(BigInt(1))((acc, next) => acc * next)
16+
17+
val result = factorials
18+
.zipWith(Source(0 to 100))((num, idx) => s"$idx! = $num")
19+
.throttle(1, 1.second)
20+
.runForeach(println)
1721

1822
implicit val ec = system.dispatcher
19-
done.onComplete(_ => system.terminate())
23+
result.onComplete(_ => system.terminate())
2024
}

0 commit comments

Comments
 (0)