reduce condition nesting

Ali Çehreli acehreli at yahoo.com
Sat Nov 25 21:42:29 UTC 2017


On 11/23/2017 06:16 AM, Andrea Fontana wrote:
> On Thursday, 23 November 2017 at 13:47:37 UTC, Adam D. Ruppe wrote:
>> On Thursday, 23 November 2017 at 05:19:27 UTC, Andrey wrote:
>>> for instance in kotlin it can be replace with this:
>>>> when {
>>>>     c1 -> foo(),
>>>>     c2 -> bar(),
>>>>     c3 -> ...
>>>>     else -> someDefault()
>>>> }
>>
>> The `switch` statement covers some of these cases too.
> 
> Anyway you can create something like this:
> https://run.dlang.io/is/7pbVXT
> 

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?

Ali


More information about the Digitalmars-d-learn mailing list