D code length vs other languages

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Tue Dec 10 03:59:09 UTC 2019


On Tuesday, 10 December 2019 at 02:46:58 UTC, norm wrote:
> ---
> new_range  = [i * i for i in range(5)   if i % 2 == 0]
> ---
> import std.range;
> auto new_range = iota(5)
>                  .filter!(i => i % 2)
>                  .map!(i => i * i);
>
> These produce different results, is that intended? I think the 
> filter should be
>
> `filter!(i => i % 2 == 0)`
>
> For your use case it makes no difference if you map first or 
> filter first. It might be useful to show a case where it does 
> matter to highlight how the UFCS allows D to give a more 
> natural order of the chained operations.
>
> Cheers,
> Norm

Done, using addition and adding the missing equality



More information about the Digitalmars-d mailing list