indexWhere

Returns optional index of the first element predicate returns true for.

indexWhere
(
alias pred
Range
)
(
Range range
,
size_t fromIndex = 0
)
if (
from!"std.range".isInputRange!Range &&
from!"bolts.traits".isUnaryOver!(pred, from!"std.range".ElementType!Range)
)

Parameters

pred

unary function that returns true for some element

range
Type: Range

the input range to search

fromIndex
Type: size_t

which index to start searching from

Return Value

Type: auto

some!size_t or none if no element was found

Examples

import optional: some, none;
assert([1, 2, 3, 4].indexWhere!(a => a % 2 == 0) == some(1));
assert([1, 2, 3, 4].indexWhere!(a => a == 5) == none);
assert([1, 2, 3, 4].indexWhere!(a => a % 2 == 0)(2) == some(3));

Meta

Since

0.0.1