Created
December 2, 2018 09:06
-
-
Save PavelZaytsev/a14555b665e21769953ca60711003fd6 to your computer and use it in GitHub Desktop.
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
trait IO[A] { | |
def run: A // case class parameters may not be call-by-name | |
// so we put unit in a singleton | |
} | |
object IO { | |
def pure[A](input: => A): IO[A] = new IO[A] { def run: A = input } | |
// again in terms of flatMap | |
def map[A, B](a: IO[A])(f: A => B): IO[B] = { | |
IO.pure(f(a.run)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment