Skip to content

Instantly share code, notes, and snippets.

@PavelZaytsev
Created December 2, 2018 09:06
Show Gist options
  • Save PavelZaytsev/a14555b665e21769953ca60711003fd6 to your computer and use it in GitHub Desktop.
Save PavelZaytsev/a14555b665e21769953ca60711003fd6 to your computer and use it in GitHub Desktop.
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