-
-
Save Jacoby6000/0198ae79578af45f4e7e9eaf6c0edd7f to your computer and use it in GitHub Desktop.
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
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