Last active
December 29, 2022 11:56
-
-
Save qingwei91/ed659763f5ee735ff0bb8efad8b216bf to your computer and use it in GitHub Desktop.
High level composition of IO
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
import cats.effect._ | |
val a = IO(...) | |
val b = IO(...) | |
a.map(transformA) // transform output of effect | |
a >> b // a then b, in other words, FlatMap | |
(a, b).parTupled // a and b concurrently, then use the output | |
IO.race(a,b) // race a and b, and cancel the slower one | |
IO.sleep(10.seconds) // non-blocking sleep |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment