What would an equivalent construct of a monad be in Ruby?
Following on the above answers:
You may be interested in checking out Rumonade, a ruby gem which implements a Monad mix-in for Ruby.
Romande is implemented as mix-in, so it expect its host class to implement the methods self.unit
and #bind
(and optionally, self.empty
), and will do the rest to make things work for you.
You can use it to map
over Option
, as you are used to in Scala, and you can even get some nice multiple-failure return values from validations, a la Scalaz's Validation class.