Skip to content

Instantly share code, notes, and snippets.

@khajavi
Created March 19, 2019 17:07
Show Gist options
  • Save khajavi/d22317ae26889897d0e0d2110906c455 to your computer and use it in GitHub Desktop.
Save khajavi/d22317ae26889897d0e0d2110906c455 to your computer and use it in GitHub Desktop.
Akka strems factorial
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