Wanted: best way to express default expectations
Paul Backus
snarwin at gmail.com
Mon Oct 14 14:44:48 UTC 2019
On Monday, 14 October 2019 at 13:00:14 UTC, Dukc wrote:
> On Saturday, 12 October 2019 at 16:48:56 UTC, Jesse Phillips
> wrote:
>>
>> 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.
>
> This is not exactly what I wanted, but probably the best
> alternative overall. At least it's better than in C#, as you
> don't sacrifice as much performance for using functional
> pipelines.
Pretty sure you don't need the foreach loop in this example; you
can just use `take`:
iota(10)
.filter!(x => x%2)
// ...
.take(1)
.each!writeln;
More information about the Digitalmars-d
mailing list