popWhile

Pops an input range while a predicate is true. Consumes the input argument.

void
popWhile
(
alias pred
Range
)
(
ref Range range
)
if (
isInputRange!Range &&
is(typeof(unaryFun!pred))
&&
isImplicitlyConvertible!(typeof(unaryFun!pred((ElementType!Range).init)), bool)
)

Parameters

pred

the predicate.

range Range

an input range, must be a lvalue.

Examples

1 string r0 = "aaaaabcd";
2 r0.popWhile!"a == 'a'";
3 assert(r0 == "bcd");
4 
5 static bool lessTwo(T)(T t)
6 {
7     return t < 2;
8 }
9 int[] r1 = [0,1,2,0,1,2];
10 r1.popWhile!lessTwo;
11 assert(r1 == [2,0,1,2]);
12 
13 static bool posLessFive(T)(T t)
14 {
15     return t < 5 && t > 0;
16 }
17 int[] r3 = [2,3,4,-1];
18 r3.popWhile!posLessFive;
19 assert(r3 == [-1]);
20 int[] r4 = [2,3,4,5];
21 r4.popWhile!posLessFive;
22 assert(r4 == [5]);

Meta