I think the Monadic null operator (a.k.a. safe property access operator)
would be pretty useful syntax sugar for mapping over option types, and
certainly help with the whole "option vs fail" for error checking because
it essentially allows monad-like functionality without actually having
(first-class) monads.
For example,
let original: Option<int> = from_str("1");
> let result: Option<Float> = original?.to_float()?.sqrt();
The `?.` operator would first check if the LHE is `Nothing`. If so, the
resulting value will just be nothing. If it's not, it will unwrap the
underlying value and call a method on the value (or reference a property if
for example it is a struct).
I think this would also be future-proof for whenever Rust gets
higher-kinded types (or if it ever does), because instead of being
hard-coded to Option it could work off a builtin Monad trait.
On Wed, Dec 11, 2013 at 1:31 PM, Nathan Myers <[email protected]> wrote:
> On 12/10/2013 12:35 PM, Ziad Hatahet wrote:
>
>> Thought this would be of interest to the list:
>> http://damieng.com/blog/2013/12/09/probable-c-6-0-features-illustrated
>>
>
> It's a good sign that nothing like most of these would add any
> value in Rust. The C# syntax hacks (old and proposed) for what
> they call "property" members only shorten badly designed code.
> Making bad code look less bad than it is should count as a
> negative. In places where there is no practical possibility
> of good code, making bad code look better may be the best one
> can do, but even there the right choice is to code somewhere
> else instead.
>
> Nathan Myers
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev