lastIndexWhere

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

lastIndexWhere
(
alias pred
Range
)
(
Range range
,
size_t fromIndex = 0
)
if (
from!"std.range".isBidirectionalRange!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 from the end 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].lastIndexWhere!(a => a % 2 == 0) == some(3));
assert([1, 2, 3, 4].lastIndexWhere!(a => a == 5) == none);
assert([1, 2, 3, 4].lastIndexWhere!(a => a % 2 == 0)(2) == some(1));

Meta

Since

0.0.1