What is the rationale behind enabling Nullable!T to be used as a regular T?
FeepingCreature
feepingcreature at gmail.com
Fri Feb 14 15:04:19 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); // []
> }
With std.typecons post deprecation:
import std.typecons;
void main() {
static import std;
const auto n = Nullable!int();
std.writeln(n.apply!(i => i + 4)); // Nullable!int()
}
More information about the Digitalmars-d
mailing list