4. Recursion
Function defined inside a function
Function calling it-self
Defining an infinite set of objects by a finite
statement (Recursion Power by Wikipedia)
Same behavior as loop, for, while, etc…
14. Monads
Deal with side-effects in a functional way
Mathematical construct
Without monads PURE FP would be nuts
Functional able todo IO
Good to Control tracking of things
Similar to AOP Interceptors
Function Composition: LINQ, Unix Pipes
You can build environments that support exactly
the features that you want (Scala Option[A])
Encapsulating two things:
control flow (Maybe, Error, List, Continuation, parser monads)
state propagation (State, Reader, Writer, IO)
16. Monads have laws…
its not just type/classes
Make possible assumptions about the
type/class and his behavior.
1. Left Identity (apply function to value)
return x >>= f (the same as) f x
sample: return 3 >>= (x -> Just (x+100000))
2. Right Identity (value to feed return)
m >>= return (the same as) m
sample: [1,2,3,4] >>= (x -> return x)
3. Associativity (no matter how nested chain)
(m >>= f) >>= g (the same as) m >>= (x -> f x >>= g)
sample: return (0,0) >>= landRight 2 >>= landLeft 2 >>= landRight 2