On Sun, 24 Oct 2010 21:39:24 +0200, bearophile <[email protected]> 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.


--
Simen

Reply via email to