binarySearch<E> function

int binarySearch<E>(
  1. List<E> sortedList,
  2. E value,
  3. {int compare(
    1. E,
    2. E

Returns a position of the value in sortedList, if it is there.

If the list isn't sorted according to the compare function, the result is unpredictable.

If compare is omitted, this defaults to calling Comparable.compareTo on the objects. In this case, the objects must be Comparable.

Returns -1 if value is not in the list.


int binarySearch<E>(List<E> sortedList, E value,
    {int Function(E, E)? compare}) {
  compare ??= defaultCompare;
  return binarySearchBy<E, E>(sortedList, identity, compare, value);