On Tue, Feb 25, 2014 at 7:24 PM, Aran Donohue <a...@fb.com> wrote:
>
>
>  Anyway, we like this feature and I'd be happy to see it adopted
> elsewhere.
>
>
There are few languages out there that take an approach like this,
including Kotlin and Fantom. I agree it is a cool feature; however, the
Option type is more general, and pattern matching is not the only way to
deal with Option variables.

map/map_or, and/and_then, or/or_else are some of the methods that can be
called on Option in Rust, while still avoiding pattern matching. Referring
to your `demo` function:

// Rust syntax
fn demo(c: Car, maybe_car: Option<Car>) {
    c.start()
    maybe_car.map(|car| car.start());
}

I am personally in favor of having something like Scala's monadic `for`
construct. Apparently this feature needs Higher Kinded Types to be
implemented in the compiler first. There has been a couple of Rust macro
implementations that offer a stop gap though:
https://mail.mozilla.org/pipermail/rust-dev/2013-May/004176.html

--
Ziad
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to