Project Elvis
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Nov 6 12:09:12 UTC 2017
On 11/05/2017 07:20 PM, Neia Neutuladh wrote:
> On Saturday, 28 October 2017 at 11:38:52 UTC, Andrei Alexandrescu wrote:
>> Walter and I decided to kick-off project Elvis for adding the homonym
>> operator to D.
>
> It's easy to write in function form:
>
> auto orElse(T)(T a, lazy T b)
> {
> return a ? a : b;
> }
>
> writeln(args[1].length.orElse(fibonacci(50)));
>
> This version can also be specialized for things like Nullable, where you
> can't necessarily cast it safely to a boolean but have a check for
> validity.
>
> Is it that valuable to have an operator for it instead?
>
>
> As an aside, I believe feepingcreature had a custom infix operator for
> this sort of thing defined, so you could write:
>
> (a /or/ b /or/ c).doStuff();
>
> The implementation (along with /and/) is left as an exercise to the reader.
If a DIP emerges, it would need to present such alternatives and argue
how it adds value over them. -- Andrei
More information about the Digitalmars-d
mailing list