@@ -1319,7 +1319,34 @@ private struct FilterBidiResult(alias pred, Range)
13191319 }
13201320}
13211321
1322- // group
1322+ /**
1323+ Groups consecutively equivalent elements into a single tuple of the element and
1324+ the number of its repetitions.
1325+
1326+ Similarly to $(D uniq), $(D group) produces a range that iterates over unique
1327+ consecutive elements of the given range. Each element of this range is a tuple
1328+ of the element and the number of times it is repeated in the original range.
1329+ Equivalence of elements is assessed by using the predicate $(D pred), which
1330+ defaults to $(D "a == b"). The predicate is passed to $(XREF functional,binaryFun),
1331+ and can either accept a string, or any callable that can be executed via
1332+ $(D pred(element, element)).
1333+
1334+ Params:
1335+ pred = Binary predicate for determining equivalence of two elements.
1336+ r = The $(XREF_PACK_NAMED range,primitives,isInputRange,input range) to
1337+ iterate over.
1338+
1339+ Returns: A range of elements of type $(D Tuple!(ElementType!R, uint)),
1340+ representing each consecutively unique element and its respective number of
1341+ occurrences in that run. This will be an input range if $(D R) is an input
1342+ range, and a forward range in all other cases.
1343+ */
1344+ Group! (pred, Range ) group(alias pred = " a == b" , Range )(Range r)
1345+ {
1346+ return typeof (return )(r);
1347+ }
1348+
1349+ // / ditto
13231350struct Group (alias pred, R) if (isInputRange! R)
13241351{
13251352 import std.typecons : Rebindable, tuple, Tuple ;
@@ -1344,12 +1371,14 @@ struct Group(alias pred, R) if (isInputRange!R)
13441371 private R _input;
13451372 private Tuple ! (MutableE, uint ) _current;
13461373
1374+ // /
13471375 this (R input)
13481376 {
13491377 _input = input;
13501378 if (! _input.empty) popFront();
13511379 }
13521380
1381+ // /
13531382 void popFront ()
13541383 {
13551384 if (_input.empty)
@@ -1370,23 +1399,27 @@ struct Group(alias pred, R) if (isInputRange!R)
13701399
13711400 static if (isInfinite! R)
13721401 {
1402+ // /
13731403 enum bool empty = false ; // Propagate infiniteness.
13741404 }
13751405 else
13761406 {
1407+ // /
13771408 @property bool empty()
13781409 {
13791410 return _current[1 ] == 0 ;
13801411 }
13811412 }
13821413
1414+ // /
13831415 @property auto ref front()
13841416 {
13851417 assert (! empty);
13861418 return _current;
13871419 }
13881420
13891421 static if (isForwardRange! R) {
1422+ // /
13901423 @property typeof (this ) save() {
13911424 typeof (this ) ret = this ;
13921425 ret._input = this ._input.save;
@@ -1396,33 +1429,6 @@ struct Group(alias pred, R) if (isInputRange!R)
13961429 }
13971430}
13981431
1399- /**
1400- Groups consecutively equivalent elements into a single tuple of the element and
1401- the number of its repetitions.
1402-
1403- Similarly to $(D uniq), $(D group) produces a range that iterates over unique
1404- consecutive elements of the given range. Each element of this range is a tuple
1405- of the element and the number of times it is repeated in the original range.
1406- Equivalence of elements is assessed by using the predicate $(D pred), which
1407- defaults to $(D "a == b"). The predicate is passed to $(XREF functional,binaryFun),
1408- and can either accept a string, or any callable that can be executed via
1409- $(D pred(element, element)).
1410-
1411- Params:
1412- pred = Binary predicate for determining equivalence of two elements.
1413- r = The $(XREF_PACK_NAMED range,primitives,isInputRange,input range) to
1414- iterate over.
1415-
1416- Returns: A range of elements of type $(D Tuple!(ElementType!R, uint)),
1417- representing each consecutively unique element and its respective number of
1418- occurrences in that run. This will be an input range if $(D R) is an input
1419- range, and a forward range in all other cases.
1420- */
1421- Group! (pred, Range ) group(alias pred = " a == b" , Range )(Range r)
1422- {
1423- return typeof (return )(r);
1424- }
1425-
14261432// /
14271433@safe unittest
14281434{
@@ -4874,13 +4880,31 @@ private struct UniqResult(alias pred, Range)
48744880 }
48754881}
48764882
4877- // permutations
4883+ /**
4884+ Lazily computes all _permutations of $(D r) using $(WEB
4885+ en.wikipedia.org/wiki/Heap%27s_algorithm, Heap's algorithm).
4886+
4887+ Returns:
4888+ A forward range the elements of which are an $(XREF range,
4889+ indexed) view into $(D r).
4890+
4891+ See_Also:
4892+ $(XREF_PACK algorithm,sorting,nextPermutation).
4893+ */
4894+ Permutations! Range permutations (Range )(Range r)
4895+ if (isRandomAccessRange! Range && hasLength! Range )
4896+ {
4897+ return typeof (return )(r);
4898+ }
4899+
4900+ // / ditto
48784901struct Permutations (Range )
48794902 if (isRandomAccessRange! Range && hasLength! Range )
48804903{
48814904 size_t [] indices, state;
48824905 Range r;
48834906
4907+ // /
48844908 this (Range r)
48854909 {
48864910 import std.range : iota;
@@ -4892,14 +4916,17 @@ struct Permutations(Range)
48924916 empty = r.length == 0 ;
48934917 }
48944918
4919+ // /
48954920 bool empty;
48964921
4922+ // /
48974923 @property auto front()
48984924 {
48994925 import std.range : indexed;
49004926 return r.indexed(indices);
49014927 }
49024928
4929+ // /
49034930 void popFront ()
49044931 {
49054932 void next (int n)
@@ -4928,23 +4955,6 @@ struct Permutations(Range)
49284955 }
49294956}
49304957
4931- /**
4932- Lazily computes all _permutations of $(D r) using $(WEB
4933- en.wikipedia.org/wiki/Heap%27s_algorithm, Heap's algorithm).
4934-
4935- Returns:
4936- A forward range the elements of which are an $(XREF range,
4937- indexed) view into $(D r).
4938-
4939- See_Also:
4940- $(XREF_PACK algorithm,sorting,nextPermutation).
4941- */
4942- Permutations! Range permutations (Range )(Range r)
4943- if (isRandomAccessRange! Range && hasLength! Range )
4944- {
4945- return typeof (return )(r);
4946- }
4947-
49484958// /
49494959unittest
49504960{
0 commit comments