Adding the ?. operator to D
Aliak
something at something.com
Thu Sep 17 05:45:10 UTC 2020
On Thursday, 17 September 2020 at 00:09:43 UTC, Paul Backus wrote:
> On Wednesday, 16 September 2020 at 19:01:28 UTC, Jacob Carlborg
> wrote:
>>
>> I would like that. It should work for an Optional/Nullable
>> type as well. It's a good idea to add an `??` operator at the
>> same time as well:
>>
>> auto a = A ?? B;
>>
>> if `A` is not null, assign `A` to `a`. Otherwise assign `B` to
>> `a`.
>
> Last time this was discussed, someone posted the following
> library version:
>
> T orElse(T)(T value, lazy T alternative)
> {
> return value ? value : alternative;
> }
>
> auto a = A.orElse(B);
Also in the same library previously mentioned:
https://aliak00.github.io/optional/optional/or/or.html
More information about the Digitalmars-d
mailing list