Mar. 29th, 2010
"hidden monads in scala"
Mar. 29th, 2010 03:20 pmblogger entry
Update: see recent blog entry on monads by Luc Duponchel for a lot more details.
Update: did you get it? for() can be applied to any class that has map(); and, roughly speaking, if you have several variables in your for loop, you will need flatMap (to flatten the result, aka, apply monadic multiplication.
trait Functor[X] { def map[Y](f: X => Y): Functor[Y] } def loop[X,Y](f: Functor[X], a: X=>Y) = for (x <- f) yield a(x)
Update: see recent blog entry on monads by Luc Duponchel for a lot more details.
Update: did you get it? for() can be applied to any class that has map(); and, roughly speaking, if you have several variables in your for loop, you will need flatMap (to flatten the result, aka, apply monadic multiplication.