Skip to content

Instantly share code, notes, and snippets.

@adilakhter
Created July 28, 2020 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adilakhter/9ca79267019a49bb16f8103c7a4cffed to your computer and use it in GitHub Desktop.
Save adilakhter/9ca79267019a49bb16f8103c7a4cffed to your computer and use it in GitHub Desktop.
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