Created
June 19, 2023 05:23
-
-
Save saswata-dutta/dbaa426e58f4f28c5be11218a62a943d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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