Comment #0 by bearophile_hugs — 2012-12-18T20:16:08Z
I suggest to add an optional argument to Nullable.get() (similar to associative array get()), that returns the given datum if the nullable is empty. This overload with one argument is nothrow:
import std.typecons;
nothrow void main() {
Nullable!int n;
int x = n.get(10); // x becomes 10.
}
See also Issue 9086
This idea is meant to allow some usage of Nullable in nothrow function, and to make Nullable more handy to use in some cases.
This idea is similar to the getOrElse method of the Option Scala object:
http://www.scala-lang.org/api/current/scala/Option.html
See also in that module how many methods Scala Option has to make its usage more handy and increase safety in absence of null.
Comment #1 by bus_dbugzilla — 2013-02-16T15:23:31Z
This would indeed be a great thing to have.
Comment #2 by github-bugzilla — 2017-08-22T16:03:15Z