Monad equivalent in Ruby

后端 未结 4 1615
野性不改
野性不改 2021-01-30 03:31

What would an equivalent construct of a monad be in Ruby?

4条回答
  •  攒了一身酷
    2021-01-30 04:00

    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.

提交回复
热议问题