Functional program design in scala
Thee cheat sheet recaps the course.
For expression and monads
for expression can always be translated into high order functions (map, flatmap, filters...)
A monad is a type which implement flatMap and a unit.
def flatMap[U](f: T => M[U]): M[U] def unit[T](x :T): M[T]
Moreover a monad must conform to 3 laws:
m flatMap f flatMap g == m flatMap (x => f(x) flatMap g)
- left unit
unit(x) flatMap f == f(x)
- right unit
m flatMap unit == m