Replacement for Zip/Lockstep

bearophile bearophileHUGS at lycos.com
Sun Mar 16 16:29:35 PDT 2014


monarch_dodra:

> Thoughts?

I have various enhancement requests or suggestions on 
zip/lockstep in Bugzilla, I suggest you to take a look at them.

I prefer the "shortest", because it's used in various languages, 
and it works well when one given range is finite and the other is 
infinite:

zip([10, 20, 7, 3), [1, -1].cycle)

I think the zip() name is the most common in languages. Adding a 
third is not easy. And I like the zip name.

I have suggested to deprecate lockstep and keep zip only:
https://d.puremagic.com/issues/show_bug.cgi?id=8155

zip(A, B) is currently not nothrow, and this is bad. I suggest to 
give it the kind of iteration (shortest/longest/etc) as template 
argument. So the shortest (that I think should be the default, as 
now), can be specialized to be nothrow:
https://d.puremagic.com/issues/show_bug.cgi?id=11913

https://d.puremagic.com/issues/show_bug.cgi?id=6034
https://d.puremagic.com/issues/show_bug.cgi?id=8715

In the ER 8715 I have suggested to add to zip _optionally_ a 
mapping function, so it becomes like zipWith of Haskell:

static struct Vec { int x, y; }
auto r2 = zip!Vec([1,2,3], [10,20,30]);

This is very handy and it's more efficient and shorter than a 
zip+map.

Bye,
bearophile


More information about the Digitalmars-d mailing list