Monad typeclass
trait Monad[F[_]]:
def pure[A](a: A): F[A]
def flatMap[A, B](fa: F[A])(f: A → F[B]): F[B]
Monad Laws
pure(a).flatMap(f) = f(a)
m.flatMap(pure) = m
m.flatMap(g).flatMap(h) = m.flatMap(b => g(b).flatMap(h))
Monad typeclass
trait Monad[F[_]]:
def pure[A](a: A): F[A]
def flatMap[A, B](fa: F[A])(f: A → F[B]): F[B]
pure(a).flatMap(f) = f(a)
m.flatMap(pure) = m
m.flatMap(g).flatMap(h) = m.flatMap(b => g(b).flatMap(h))