Option!T

Sebastian Graf via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 1 10:08:16 PDT 2014


On Tuesday, 1 July 2014 at 16:49:38 UTC, Nick Sabalausky wrote:
> On 12/10/2013 12:40 PM, JR wrote:
>> On Tuesday, 10 December 2013 at 17:28:26 UTC, Andrei 
>> Alexandrescu wrote:
>>> We have only(x) 
>>> (http://dlang.org/phobos/std_range.html#.only) to be a
>>> collection of exactly one value, but not a type for "a value 
>>> of type T
>>> or nothing at all".
>>
>> Is this not what Nullable!T is?
>
> Nullable lacks compile-time enforcement that you handle the 
> "does not exist" possibility. It turns it into a run-time issue.

I'd say, if we include an Option type, then that type should wrap 
a Nullable rather than a range. Conversion to a range can still 
happen through a function, and Option could enforce proper 
pattern matching or ifHasValue!projection.orElse(nullValue); goo.



More information about the Digitalmars-d mailing list