Improving std.range.Zip

Tomek Sowiński just at ask.me
Mon Oct 25 12:20:24 PDT 2010


Dnia 25-10-2010 o 08:42:31 KennyTM~ <kennytm at gmail.com> napisał(a):

> On Oct 25, 10 14:04, Andrei Alexandrescu wrote:
>> This is coming full circle. At a point, map _did_ support multiple
>> ranges. Some people found that non-modular - if you want multiple
>> ranges, you should use map with zip...
>
> Except that at "that point"[1], map's multi-range support is equivalent  
> to
>
>      map!(func)(r1, r2, r3...) ==  map!(func)(chain(r1, r2, r3...))
>
> which is hardly useful. OTOH zipWithN is a very useful higher-order  
> function.
>
> [1]:  
> http://web.archive.org/web/20080417051734/www.digitalmars.com/d/2.0/phobos/std_algorithm.html#map

You're right. Still, modularity is a valid point. Thinking about it, this  
can be a good exercise in static inheritance -- make Zip the base taking  
care of multi-range traversal (stopping policy, etc) and the "derived"  
ranges (Map, Filter, Reduce) would only implement element accessors,  
transformation, and so on.

-- 
Tomek


More information about the Digitalmars-d mailing list