Saturday, June 11, 2011

Monads for Java Programmer

http://irekjozwiak.com/entry/2009/06/13/Monads-for-Java-C---programmers.html

(>>=) bind
a1 >>= a2 = join (fmap a2 a1)
 
fmap _            Nothing       = Nothing
fmap someFunction (Just a)      = Just (someFunction a)
 
> fmap (+ 2) (Just 4)
Just 6
> fmap (+ 2) (Nothing)
Nothing
join Nothing         = Nothing
join (Just Nothing) = Nothing
join (Just (Just x)) = Just x