The forward range to be split.
A unary predicate for deciding where to split the range.
A forward range of slices of the original range split by whitespace.
import std.ascii : isWhite; import std.algorithm.comparison : equal; import std.algorithm.iteration : splitter; string str = "Hello World\t!"; assert(str.splitter!(isWhite).equal(["Hello", "World", "!"]));
import std.algorithm.comparison : equal; import std.range.primitives : front; assert(equal(splitter!(a => a == '|')("a|bc|def"), [ "a", "bc", "def" ])); assert(equal(splitter!(a => a == ' ')("hello world"), [ "hello", "", "world" ])); int[] a = [ 1, 2, 0, 0, 3, 0, 4, 5, 0 ]; int[][] w = [ [1, 2], [], [3], [4, 5], [] ]; assert(equal(splitter!(a => a == 0)(a), w)); a = [ 0 ]; assert(equal(splitter!(a => a == 0)(a), [ (int[]).init, (int[]).init ])); a = [ 0, 1 ]; assert(equal(splitter!(a => a == 0)(a), [ [], [1] ])); w = [ [0], [1], [2] ]; assert(equal(splitter!(a => a.front == 1)(w), [ [[0]], [[2]] ]));
Lazily splits a range r whenever a predicate isTerminator returns true for an element.
As above, two adjacent separators are considered to surround an empty element in the split range.