lib/kleisli/maybe.rb in kleisli-0.1.0 vs lib/kleisli/maybe.rb in kleisli-0.2.0

- old
+ new

@@ -14,10 +14,18 @@ def ==(other) value == other.value end + def *(other) + self >-> f { + other >-> val { + Maybe.lift(f.arity > 1 ? f.curry.call(val) : f.call(val)) + } + } + end + class None < Maybe def fmap(&f) self end @@ -26,10 +34,15 @@ end def or(other) other end + + def to_s + "None" + end + alias inspect to_s end class Some < Maybe def initialize(value) @value = value @@ -44,9 +57,14 @@ end def or(other) self end + + def to_s + "Some(#{@value})" + end + alias inspect to_s end end end Maybe = Kleisli::Maybe.method(:lift)