Function indexWhere

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

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

NameDescription
pred unary function that returns true for some element
range the input range to search
fromIndex which index 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].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));