Live coding session
L2L Warszawa 2019
Sławomir Śledź
Senior Java/Scala Developer
What is a monad?
In functional programming monad is a design pattern which is used to express how states of computations are changing
In category theory monad is an endofunctor (a functor mapping a category to itself), together with two natural transformations
We can think about monad like about some smart container keeping some value or values.
This container abstracts away from how this value is kept.
We can have a container
Monad consists of three parts:
return(x) : T → M T
(mx >>= f) : (M T, T → M U) → M U
return a >>= f ≡ f a
m >>= return ≡ m
(m >>= f) >>= g ≡ m >>= (\x -> f x >>= g)
trait Monad[M[_]] {
def pure[A](x: A): M[A]
def flatMap[A, B](xs: M[A])(f: A => M[B]): M[B]
}
Let's do some coding :-)
Thank you :-)