A (perhaps crude) exploration of the Maybe Monad in Ruby.

I realize this is somewhat treaded turf, however it was done for my own learning, and I think came out pretty clean!  Needs tests and could be made more flexible, yada yada.


  nil.maybe { |n| n + 2 + 3 }

  => nil 

Which is essentially the same as nil.try(:+, 1).try(:+, 2).try(:+, 3) If the result is nil anywhere in the chain, the block simply returns nil

blog comments powered by Disqus