binarySearchBy<K extends Comparable?> method

int binarySearchBy<K extends Comparable?>({
  1. required K? selector(
    1. E element
    ),
  2. K? key,
  3. int? fromIndex,
  4. int? toIndex,
})

Searches this List or its range for an element having the key returned by the specified selector function equal to the provided key value using the binary search algorithm. The List is expected to be sorted into ascending order according to the Comparable natural ordering of keys of its elements. otherwise the result is undefined.

Implementation

int binarySearchBy<K extends Comparable?>({
  required K? Function(E element) selector,
  K? key,
  int? fromIndex,
  int? toIndex,
}) =>
    binarySearchWithComparison(
      comparison: (element) =>
          key == null ? 1 : selector(element)?.compareTo(key) ?? -1,
      fromIndex: fromIndex,
      toIndex: toIndex,
    );