index<E> function
int?
index<E>(
- List<
E> a, - E x, {
- Comparator<
E> ? compare, - ToKey<
E, Object> ? key, - int lo = 0,
- int? hi,
Locate the leftmost value exactly equal to x
Implementation
int? index<E>(List<E> a, E x,
{Comparator<E>? compare, ToKey<E, Object>? key, int lo = 0, int? hi}) {
// todo unit-test custom compare and key
compare = argToComparator<E>(compare, key);
final i = bisect_left(a, x, compare: compare, lo: lo, hi: hi);
if (i != a.length && compare(a[i], x) == 0) {
return i;
}
throw ArgumentError('Value not found');
}