Improving std.range.Zip

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Oct 24 23:04:07 PDT 2010


On 10/24/10 14:55 CDT, Simen kjaeraas wrote:
> On Sun, 24 Oct 2010 21:39:24 +0200, bearophile
> <bearophileHUGS at lycos.com> wrote:
>
>> Tomek S.:
>>
>>> map!((a) {return myNaryFun(a._0, a._1, ...); })(zip(range1, range2,
>>> ...));
>>
>> Currently the docs of std.algorithm.map say:
>>
>>> Multiple functions can be passed to map. In that case, the element
>>> type of map is a tuple containing one element for each function.<
>>
>> But lot of time ago I have said that in my opinion that's not the best
>> design. Python has a different design, its map does what you want, you
>> may write your code in Python as:
>>
>> map(myNaryFun, range1, range2, ...)
>>
>> An example (Python 2.6):
>>
>>>>> a = ["a", "b", "c", "d"]
>>>>> b = [1, 2, 3, 4]
>>>>> map(lambda c,n: c * n, a, b)
>> ['a', 'bb', 'ccc', 'dddd']
>>
>> Is is possible to change the std.algorithm.map to a semantics similar
>> to the Python one, that I think is more useful?
>
>  From what I can see, map currently simply doesn't support passing it
> multiple ranges. It would be a trivial change to let it support multiple
> ranges in addition to multiple functions.

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

Andrei



More information about the Digitalmars-d mailing list