compareListsBy<T> function

int compareListsBy<T>(
  1. List<T> a,
  2. List<T> b,
  3. int compare(
    1. T a,
    2. T b
    )
)

Implementation

int compareListsBy<T>(List<T> a, List<T> b, int Function(T a, T b) compare) {
  var aLength = a.length;
  var bLength = b.length;
  var minLength = aLength < bLength ? aLength : bLength;
  for (var i = 0; i < minLength; i++) {
    var result = compare(a[i], b[i]);
    if (result != 0) return result;
  }
  return aLength - bLength;
}