2010/10/24 Tomek Sowiński <[email protected]>: > I have noticed an emerging idiom in my code lately: bring together n ranges, > transform them to one range using a n-ary function. Currently it's achieved > with: > > map!((a) {return myNaryFun(a._0, a._1, ...); })(zip(range1, range2, ...)); > > It's a bit of a nuisanse -- rarely do my transforming functions take tuples, > and there's the necessity of composing 2 higher-order ranges to render > fairly common functionality. I think Zip could be further parametrized with > a zipper function, so that the above code would boil down to: > > zip!myNaryFun(range1, range2, ...); > > Having looked at Zip's source, such change shouldn't be a big deal. Oh, and > the default zipper function would be std.typecons.tuple, not to trouble > those not keen on generalization.
That's what Haskell calls ZipWith. I called it tmap (as in tuple-map) when I needed it in D. IMHO, it should be a generalization of std.algorithm.map: let it accept n ranges and a n-ary function. It can even do a partial check at compile-time. Extending filter() and reduce() to work with n ranges in parallel and a n-args function is also useful. you may be interested in looking there: http://www.dsource.org/projects/dranges/ (more specifically, in the algorithm module) Philippe
