reduce condition nesting
Ali Çehreli
acehreli at yahoo.com
Sat Nov 25 22:45:03 UTC 2017
On 11/25/2017 02:05 PM, Adam D. Ruppe wrote:
> On Saturday, 25 November 2017 at 21:42:29 UTC, Ali Çehreli wrote:
>> I tried to implement the following but gave up because I could not
>> ensure short circuit behaviour.
>>
>> when(
>> c1.then(foo()),
>> c2.then(bar()),
>> otherwise(zar())
>> );
>>
>> Possible?
>
> Bones: "Perhaps the professor can use your computer."
>
> https://dlang.org/spec/function.html#lazy_variadic_functions
>
> Dr. Nichols: "Lazy variadic functions?!"
> Scotty: "That's the ticket, laddie."
>
> ---
> import std.stdio;
>
> void when(bool delegate()[] foo...) {
> foreach(i; foo) {
> if(i())
> return;
> }
> }
Cool! So, D is great even without templates. ;)
Despite 'lazy', apparently my failed attempt had eager arguments:
void when(lazy bool[] args...) {
// ...
}
Ali
More information about the Digitalmars-d-learn
mailing list