takeBackWhile

Returns a lazy input range that takes from the input tail while a predicate is verified and the input is not empty.

takeBackWhile
(
alias pred
Range
)
(
auto ref Range range
)
if (
isBidirectionalRange!Range &&
is(typeof(unaryFun!pred))
&&
isImplicitlyConvertible!(typeof(unaryFun!pred((ElementType!Range).init)), bool)
)

Parameters

pred

the predicate.

range
Type: Range

an bidirectional range, only consumed when passed by reference.

Examples

1 import std.range: array;
2 import std.ascii: isDigit;
3 auto r = "A123";
4 assert(takeBackWhile!((a) => isDigit(a))(r).array == "321");
5 assert(r == "A");
6 assert(takeBackWhile!((a) => isDigit(a))(r).array == "");
7 assert(takeBackWhile!((a) => isDigit(a))("").array == "");

Meta