index<E> function

int? index<E>(
  1. List<E> a,
  2. E x, {
  3. Comparator<E>? compare,
  4. ToKey<E, Object>? key,
  5. int lo = 0,
  6. 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');
}