[Issue 6788] std.range.pairwise
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Nov 7 17:11:36 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=6788
--- Comment #13 from Andrei Alexandrescu <andrei at erdani.com> ---
I see in https://docs.python.org/2/library/itertools.html that the recipe given
for pairwise would produce the pairs (1, 2), (2, 3), and (3, 4) starting from
[1, 2, 3, 4]. So defining it with different semantics is potentially confusing.
The functionality proposed is really "combinations of 2 elements in the given
range". In general we'd be looking at combinations of k elements of the given
range, yielding a range of k-tuples. See
https://en.wikipedia.org/wiki/Combination
Fittingly enough, Python offers
https://docs.python.org/2/library/itertools.html#itertools.combinations and
https://docs.python.org/2/library/itertools.html#itertools.combinations_with_replacement
I think ws should define a function as follows:
auto combinations(uint k, Flag!"Duplicates" f = Duplicates.no, R)(R range);
The function returns a range of k-tuples containing combinations of elements in
the range. Depending on the flag, duplicates are present or not.
--
More information about the Digitalmars-d-bugs
mailing list