Probable C# 6.0 features

Jacob Carlborg doob at me.com
Wed Dec 11 07:50:54 PST 2013


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


More information about the Digitalmars-d mailing list