Hacker News new | ask | show | jobs
by chriswarbo 4508 days 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://stackoverflow.com/questions/14178889/reader-monad-pur...

1 comments

Oh, 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-patte...