Skip to content

Instantly share code, notes, and snippets.

@Jacoby6000
Forked from anonymous/Futures.scala
Last active November 1, 2016 21:29
Show Gist options
  • Save Jacoby6000/0198ae79578af45f4e7e9eaf6c0edd7f to your computer and use it in GitHub Desktop.
Save Jacoby6000/0198ae79578af45f4e7e9eaf6c0edd7f to your computer and use it in GitHub Desktop.
def parallelPaper(lines: List[String]): Future[Int] = {
val computingCounts: List[Future[Int]] = lines.map(line => parallelCompute(line))
val futureComputedCounts: Future[List[Int]] = Future.sequence(computingLines)
val resultFuture: Future[Int] =
futureComputedCounts.map { counts =>
val accumulatorInitialValue = 0
counts.foldLeft(accumulatorInitialValue)((accumulator, nextCount) => accumulator + nextCount)
}
resultFuture
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment