Module ddash.algorithm.index
Returns an optional
index of an element.
Example
import ddash .utils .optional: some, none;
auto arr1 = [1, 2, 3, 4];
assert(arr1 .indexWhere!(a => a % 2 == 0) == some(1));
assert(arr1 .lastIndexWhere!(a => a % 2 == 0) == some(3));
assert(arr1 .indexWhere!(a => a == 5) == none);
assert(arr1 .lastIndexWhere!(a => a % 2 == 0)(2) == some(1));
auto arr2 = [1, 2, 1, 2];
assert(arr2 .indexOf(2) == some(1));
Functions
Name | Description |
---|---|
indexOf(range, value, fromIndex)
|
Finds the first element in a range that equals some value |
indexWhere(range, fromIndex)
|
Returns optional index of the first element predicate returns true for.
|
lastIndexOf(range, value, fromIndex)
|
Finds the first element in a range that equals some value |
lastIndexWhere(range, fromIndex)
|
Returns optional index of the last element predicate returns true for.
|