[OT] Some neat ideas from the Kotlin language
Nemanja Boric via Digitalmars-d
digitalmars-d at puremagic.com
Fri Feb 19 04:28:14 PST 2016
On Friday, 19 February 2016 at 12:16:49 UTC, Jacob Carlborg wrote:
> I like the way it's used in Scala:
>
> val a = Option(value)
> val b = a.map(e => e /* do something with the unrapped
> e).getOrElse(/* use a default value here */)
>
> The Option type in Scala acts like a zero or one element
> collection. The Scala way can be implemented in D as well
> without any language support.
>
IMHO, without language support looks really bad - `map` really
sticks out here.
What Rust is doing:
```
let foo: Option<i32> = bar();
let new_stuff = match foo {
Some(x) => x,
None => 0
}
```
(or similar, I don't have compiler handy).
More information about the Digitalmars-d
mailing list