August 2018
Intermediate to advanced
380 pages
10h 2m
English
Consider that we need to compute a sum of two ranges, and then sum the results. A naive way to combine is as follows:
def sequential: IO[Int] = for { s1 <- sum(1 , 10) s2 <- sum(10, 20) } yield s1 + s2
In the preceding code, we combine our computations using the Monadic flow. Let's see what happens if we try and run the competition under a benchmark function:
benchmarkFlush(sequential).unsafeRunSync
The result of the preceding execution is as follows:

First, notice that the first range gets computed first. The second range does not even start until the first range finishes. Also notice how both of the threads ...