Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def par_fib_(n: Int): Long = {
- def fibHelper(n: Int): Future[Long] =
- if (n<=46) Future{ fib(n) } else {
- val f1: Future[Long] = fibHelper(n-1)
- val f2: Future[Long] = fibHelper(n-2)
- // Await.result(f1, Duration.Inf) + Await.result(f2, Duration.Inf)
- for { nf1 <- f1
- nf2 <- f2 } yield nf1 + nf2
- f1.flatMap( nf1 => f2.map ( nf2 => nf1 + nf2 ) )
- }
- // NOTE: the 'join' form, converting Future[Long] to Long
- Await.result(fibHelper(n), Duration.Inf)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement