takeWhile

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

takeWhile
(
alias pred
Range
)
(
auto 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, only consumed when passed by reference.

Examples

import std.range: array;
import std.ascii: isDigit;
auto r = "012A";
assert(takeWhile!((a) => isDigit(a))(r).array == "012");
assert(r == "A");
assert(takeWhile!((a) => isDigit(a))(r).array == "");
assert(takeWhile!((a) => isDigit(a))("").array == "");

Meta