feature request: N-ary map

Timothee Cour thelastmammoth at gmail.com
Fri Jun 21 17:07:26 PDT 2013


On Fri, Jun 21, 2013 at 4:14 PM, Timothee Cour <thelastmammoth at gmail.com>wrote:

> On Fri, Jun 21, 2013 at 4:02 PM, Ali Çehreli <acehreli at yahoo.com> wrote:
>
>> On 06/21/2013 03:57 PM, Diggory wrote:
>>
>>> On Friday, 21 June 2013 at 22:56:04 UTC, Andrei Alexandrescu wrote:
>>>
>>>> On 6/21/13 3:55 PM, Andrei Alexandrescu wrote:
>>>>
>>>>> On 6/21/13 3:45 PM, Timothee Cour wrote:
>>>>>
>>>>>> I'd like to support N-ary map, ie std.algorithm.map that takes 1 or
>>>>>> more
>>>>>> ranges as arguments and operates lazily on those.
>>>>>>
>>>>>
>>  You can use "zip" from std.range.
>>>
>>
>> Timothee specifically said that he is trying to avoid zip: :)
>>
>>
>> > before:
>> >   zip(a,b).map!(u=>absDiff(u[0],**u[1])).reduce!fun;
>> > after:
>> >   map!absDiff(a,b).reduce!fun;
>>
>> Ali
>>
>
> also works great with string lambdas:
> eg: dotproduct:
>
> before:
>   zip(u,v).map!"a[0]*a[1]".reduce!"a+b";
> after:
>   map!"a*b"(u,v).reduce!"a+b";
>
> => clearer, and provides more room for optimizaton
>
>

actually the version without the proposed N-ary map is even worse, because
zip uses StoppingPolicy.shortest by default (which i find weird and
contrary to D's safe by default stance):

here's the (corrected) dotproduct:

before:
  zip(StoppingPolicy.requireSameLength,u,v).map!"a[0]*a[1]".reduce!"a+b";
after:
  map!"a*b"(u,v).reduce!"a+b";

i think it's a clear improvement in terms of clarity (and again,
optimizations possible).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130621/0835210a/attachment.html>


More information about the Digitalmars-d mailing list