Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NaiveParMapN
object Ex11 extends IOApp {
def naiveParMapN[A, B] (io1: IO[A], io2: IO[B]): IO[(A, B)] = {
io1.start.bracket { f1 =>
io2.start.bracket { f2 =>
for {
a <- f1.join
b <- f2.join
} yield (a, b)
}(_.cancel)
}(_.cancel)
}
def run(args: List[String]): IO[ExitCode] = {
import com.innerproduct.ee.debug._
val a = IO(1).debug()
val b = IO(2).debug()
naiveParMapN(a, b).debug().flatMap(_ => IO.pure(ExitCode.Success))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment