Project Elvis
    Neia Neutuladh 
    neia at ikeran.org
       
    Mon Nov  6 00:20:09 UTC 2017
    
    
  
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.
    
    
More information about the Digitalmars-d
mailing list