3 ms·
This has a fancy name: The Reader Monad. Don't be scared though! Essentially it's a way of composing functions together, like a(b(c(d(...)))), but it 'skips' t
by chriswarbo 13y ago
This has a fancy name: The Reader Monad.
Don't be scared though! Essentially it's a way of composing functions together, like a(b(c(d(...)))), but it 'skips' the first argument of every function, leaving a 'hole'. We get back a function which plugs its argument into all of these holes, ie. dependency injection!
I found these links useful for understanding the technique:
http://lambdaman.blogspot.co.uk/2007/10/monadreader.html http://lambdaman.blogspot.co.uk/2007/10/monadreader.html
http://stackoverflow.com/questions/14178889/reader-monad-purpose http://stackoverflow.com/questions/14178889/reader-monad-pur...
- pkinsky 13y agoOh, cool! I've seen examples of the Reader monad in Scala, but we use the Cake pattern for dependency injection (self types and multiple inheritance) http://www.cakesolutions.net/teamblogs/2011/12/19/cake-pattern-in-depth/ http://www.cakesolutions.net/teamblogs/2011/12/19/cake-patte...