feature request: N-ary map

Timothee Cour thelastmammoth at gmail.com
Fri Jun 21 15:45:37 PDT 2013


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.

example: suppose we have a 2 argument function, eg : auto absDiff(a,b){...}
before:
  zip(a,b).map!(u=>absDiff(u[0],u[1])).reduce!fun;
after:
  map!absDiff(a,b).reduce!fun;

currently the signature of std.algorithm.map is:
auto map(Range)(Range r) if (isInputRange!(Unqual!Range));
new signature:
auto map(Range...)(Range r) if (Range.length>0 &&
allSatisfy!(isInputRange!Unqual,Range));

implementation:
it can be implemented using zip and expand, but there is room for more
optimization potentially. Or will LDC/GDC be smart enough to have zero
overhead when using zip?

advantages:
concise and natural syntax
reduces need for zip, and adds optimization opportunities
reduces need for using foreach when zip is too confusing
no code breakage
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130621/229c678c/attachment.html>


More information about the Digitalmars-d mailing list