Function lastIndexWhere

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

auto auto 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

NameDescription
pred unary function that returns true for some element
range the input range to search
fromIndex which index from the end to start searching from

Returns

some!size_t or none if no element was found

Since

0.0.1

Example

import ddash.utils.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));