splitWhen

fnauto splitWhen(alias pred, Range)(Range r) if (is(typeof(binaryFun!pred(r.front, r.front)) : bool) && isForwardRange!Range)

Splits a forward range into subranges in places determined by a binary predicate called with adjacent elements.

When iterating, one element of r is compared with pred to the next element. If pred returns true, a new subrange is started for the next element. Otherwise, they are part of the same subrange.

If the elements are compared with an inequality (!=) operator, consider

chunkBy instead, as it's likely faster to execute.

Parameters

predPredicate for determining where to split. The earlier element in the source range is always given as the first argument.
rA forward range to be split.

Returns

A range of subranges of r, split such that within a given subrange,

calling pred with any pair of adjacent elements as arguments returns false. Copying the range currently has reference semantics, but this may change in the future.

See_also:

splitter, which uses elements as splitters instead of element-to-element

relations.