Wanted: best way to express default expectations
Jesse Phillips
Jesse.K.Phillips+D at gmail.com
Sat Oct 12 16:48:56 UTC 2019
On Saturday, 12 October 2019 at 16:24:01 UTC, Jesse Phillips
wrote:
> 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.
Sorry forgot the foreach break part.
import std.stdio;
void main()
{
import std.algorithm;
import std.range;
foreach(i; iota(10)
.filter!(x => x%2)
.until!(x => x>5)
.map!"a * a"
.filter!(x => x%4)) {
i.writeln;
break;
}
}
Note this is all done lazily so there is no walking of the iota
which happens.
More information about the Digitalmars-d
mailing list