D code length vs other languages

norm norm.rowtree at gmail.com
Tue Dec 10 02:46:58 UTC 2019


On Tuesday, 10 December 2019 at 02:23:21 UTC, Jesse Phillips 
wrote:
> On Monday, 9 December 2019 at 16:33:30 UTC, Steven 
> Schveighoffer wrote:
>> On 12/7/19 4:28 AM, Jesse Phillips wrote:
>>> On Friday, 6 December 2019 at 20:09:46 UTC, Paolo Invernizzi 
>>> wrote:
>>>> [...]
>>> 
>>> https://dev.to/jessekphillips/map-reduce-in-d-25nm
>>> 
>>> This was my very brief comparison of List comprehension vs Ds 
>>> libraries.
>>
>> "In the first situation filtering came before the operation, 
>> here it will ultimately be useless because it operates on the 
>> square of a number which is always even."
>>
>> You sure about that? ;)
>>
>> -Steve
>
> Yes because anything else is filtered out.
>
> I must have been thinking about addition :)

---
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


More information about the Digitalmars-d mailing list