Skip to content

Commit d9fd09d

Browse files
authored
[std.algorithm.iteration] Tweak splitter, splitWhen docs (#10733)
Update splitter cheat sheet for non-separator overloads. Add constraint for splitWhen's `pred`. `splitter!isTerminator` always returns a forward range.
1 parent ff612b8 commit d9fd09d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

std/algorithm/iteration.d

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ $(T2 reduce,
5252
$(T2 splitWhen,
5353
Lazily splits a range by comparing adjacent elements.)
5454
$(T2 splitter,
55-
Lazily splits a range by a separator.)
55+
Lazily splits a range by a separator, element predicate or whitespace.)
5656
$(T2 substitute,
5757
`[1, 2].substitute(1, 0.1)` returns `[0.1, 2]`.)
5858
$(T2 sum,
@@ -3010,10 +3010,10 @@ if (isInputRange!Range)
30103010

30113011
/**
30123012
Splits a forward range into subranges in places determined by a binary
3013-
predicate.
3013+
predicate called with adjacent elements.
30143014
30153015
When iterating, one element of `r` is compared with `pred` to the next
3016-
element. If `pred` return true, a new subrange is started for the next element.
3016+
element. If `pred` returns true, a new subrange is started for the next element.
30173017
Otherwise, they are part of the same subrange.
30183018
30193019
If the elements are compared with an inequality (!=) operator, consider
@@ -3023,7 +3023,8 @@ Params:
30233023
pred = Predicate for determining where to split. The earlier element in the
30243024
source range is always given as the first argument.
30253025
r = A $(REF_ALTTEXT forward range, isForwardRange, std,range,primitives) to be split.
3026-
Returns: a range of subranges of `r`, split such that within a given subrange,
3026+
3027+
Returns: A range of subranges of `r`, split such that within a given subrange,
30273028
calling `pred` with any pair of adjacent elements as arguments returns `false`.
30283029
Copying the range currently has reference semantics, but this may change in the future.
30293030
@@ -3033,7 +3034,7 @@ relations.
30333034
*/
30343035

30353036
auto splitWhen(alias pred, Range)(Range r)
3036-
if (isForwardRange!Range)
3037+
if (is(typeof(binaryFun!pred(r.front, r.front)) : bool) && isForwardRange!Range)
30373038
{ import std.functional : not;
30383039
return ChunkByImpl!(not!pred, not!pred, GroupingOpType.binaryAny, Range)(r);
30393040
}
@@ -5537,9 +5538,9 @@ Returns:
55375538
one separator is given, the result is a range with two empty elements.
55385539
55395540
See_Also:
5540-
$(REF _splitter, std,regex) for a version that splits using a regular expression defined separator,
5541-
$(REF _split, std,array) for a version that splits eagerly and
5542-
$(LREF splitWhen), which compares adjacent elements instead of element against separator.
5541+
- $(REF _splitter, std,regex) for a version that splits using a regular expression defined separator.
5542+
- $(REF _split, std,array) for a version that splits eagerly.
5543+
- $(LREF splitWhen), which compares adjacent elements instead of element against separator.
55435544
*/
55445545
auto splitter(alias pred = "a == b",
55455546
Flag!"keepSeparators" keepSeparators = No.keepSeparators,
@@ -6318,8 +6319,7 @@ Params:
63186319
deciding where to split the range.
63196320
63206321
Returns:
6321-
An $(REF_ALTTEXT input range, isInputRange, std,range,primitives) of slices of
6322-
the original range split by whitespace.
6322+
A forward range of slices of the original range split by whitespace.
63236323
+/
63246324
auto splitter(alias isTerminator, Range)(Range r)
63256325
if (isForwardRange!Range && is(typeof(unaryFun!isTerminator(r.front))))

0 commit comments

Comments
 (0)