Skip to content

Instantly share code, notes, and snippets.

@saswata-dutta
Created June 19, 2023 05:23
Show Gist options
  • Save saswata-dutta/dbaa426e58f4f28c5be11218a62a943d to your computer and use it in GitHub Desktop.
Save saswata-dutta/dbaa426e58f4f28c5be11218a62a943d to your computer and use it in GitHub Desktop.
case class MyIo[A](unsafeRun : () => A) {
def map[B](f: A => B): MyIo[B] = MyIo(() => f(unsafeRun()))
def flatMap[B](f: A => MyIo[B]): MyIo[B] = MyIo(() => f(unsafeRun()).unsafeRun())
}
val printer = MyIo(() => println("how"))
val doit = printer.flatMap( _ => printer)
val other = printer.map( _ => println("w"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment