Skip to content

Instantly share code, notes, and snippets.

@qingwei91
Last active December 29, 2022 11:56
Show Gist options
  • Save qingwei91/ed659763f5ee735ff0bb8efad8b216bf to your computer and use it in GitHub Desktop.
Save qingwei91/ed659763f5ee735ff0bb8efad8b216bf to your computer and use it in GitHub Desktop.
High level composition of IO
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