splitWhen method
Splits this collection into a lazy Iterable, where each split will be
make if predicate returns true for a pair of entries.
For example, one could split the iterable at each changed value like this:
final list = [1, 1, 1, 2, 2, 1, 4, 4];
final splitted = list.splitWhen((a, b) => a != b);
In that example, splitted would consist of [1, 1, 1, 1], [2, 2],
[1], [4, 4].
See also:
- chunkWhile, which works similarly but with a reverted
predicate.
Implementation
Iterable<List<E>> splitWhen(bool Function(E, E) predicate) {
return chunkWhile((a, b) => !predicate(a, b));
}