On 2013-12-11 16:10, Ary Borenszweig wrote:

By the way, in Crystal we currently have:

class Object
   def try
     yield
   end
end

class Nil
   def try(&block)
     nil
   end
end

You can use it like this:

foo.try &.bar
foo.try &.bar.try &.baz

Not the nicest thing, but it's implemented as a library solution. Then
you could have syntactic sugar for that.

Again, I don't see why this is related to monads. Maybe because monads
are boxes that can perform functions, anything which involves a
transform can be related to a monad. :-P

It's like in Ruby with ActiveSupport:

a = foo.try(:bar).try(:x)

--
/Jacob Carlborg

Reply via email to