Created
July 28, 2020 17:55
-
-
Save adilakhter/9ca79267019a49bb16f8103c7a4cffed to your computer and use it in GitHub Desktop.
NaiveParMapN
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
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