Wanted: best way to express default expectations

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Sat Oct 12 16:24:01 UTC 2019


On Thursday, 10 October 2019 at 11:50:59 UTC, Dukc wrote:
> On Thursday, 10 October 2019 at 11:47:21 UTC, Dukc wrote:
>> On Thursday, 10 October 2019 at 11:44:58 UTC, Nicholas Wilson 
>> wrote:
>>>
>>> https://dlang.org/phobos/std_algorithm_iteration.html#.filter
>>
>> For loops, that's an excellent choice. But what about early 
>> function returns?
>
> And also, sometimes it's not practical to filter the range up 
> front. You may also want to shortcut out in middle of the 
> `foreach` body, or `break` out of an outer loop, or `return` 
> instead of just aborting the loop.

Ignore the result has no meaning


import std.stdio;
void main()
{
import std.algorithm;
import std.range;

iota(10)
    .filter!(x => x%2)
     .until!(x => x>5)
     .map!"a * a"
    .filter!(x => x%4).writeln;
}



More information about the Digitalmars-d mailing list