What is the rationale behind enabling Nullable!T to be used as a regular T?

Petar Petar
Fri Feb 14 14:08:06 UTC 2020


On Friday, 14 February 2020 at 12:40:54 UTC, Adnan wrote:
> On Friday, 14 February 2020 at 10:35:52 UTC, DanielG wrote:
>> There's also the 'optional' package if you're looking for 
>> something more functional-program-ey:
>>
>> https://code.dlang.org/packages/optional
>
> Not sure if this is any better
>
> /+dub.sdl:
> dependency "optional" version="~>1.0.0"
> +/
> import optional;
>
> void main(const string[] args) {
>     static import std;
>     const auto n = no!int();
>     std.writeln(n + 4); // []
> }

It's by design. optional presents a range interface of length 0 
or 1.

See the docs for more info: 
https://github.com/aliak00/optional/#summary


More information about the Digitalmars-d mailing list