Created
March 19, 2019 17:07
-
-
Save khajavi/d22317ae26889897d0e0d2110906c455 to your computer and use it in GitHub Desktop.
Akka strems factorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Factorial extends App { | |
implicit val system = ActorSystem("QuickStart") | |
implicit val materializer = ActorMaterializer() | |
val source: Source[Int, NotUsed] = Source(1 to 100) | |
val factorials: Source[BigInt, NotUsed] = source.scan(BigInt(1))((acc, next) => acc * next) | |
val result: Future[IOResult] = | |
factorials | |
.map(num => ByteString(s"$num\n")) | |
.runWith(FileIO.toPath(Paths.get("factorials.txt"))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment