In D you can do the following to create pair wise tuples of array elements:
auto a = [0, 1, 2, 3, 4];
auto x = a.zip(a.save.dropOne);
x
can now be expanded to [[0, 1], [1, 2], [2, 3], [3, 4]]
.
I would like to generalize this concept to create n-tuples like this:
auto i = 0;
auto x = zip(generate!(() => a.save.dropExactly(i++)).take(n));
However, this leads to x
being a range of Tuple!([1, 2, 3, 4]), Tuple!([2, 3, 4])
for n = 2.
This is plausible, since take
produces subranges. But how can I create separate ranges to achieve the intended behavior?
Thanks in advance.
x
to[[0, 1], [1, 2], [2, 3], [3, 4]]
usinggenerate
.