getValuesByIndexes<V> method

List<(D, V)> getValuesByIndexes<V>(
  1. Iterable<int> indexes,
  2. List<V> values
)

Returns (ID, value) pairs for the given indexes.

values must be aligned with this collection's ids internal ordering.

Implementation

List<(D, V)> getValuesByIndexes<V>(Iterable<int> indexes, List<V> values) {
  List<(D, V)> valuesByIndexes;

  if (values.length < _ids.length) {
    valuesByIndexes = indexes
        .map((i) {
          if (i < values.length) {
            var id = _ids[i];
            return (id, values[i]);
          } else {
            return null;
          }
        })
        .nonNulls
        .toList();
  } else {
    valuesByIndexes = indexes.map((i) {
      var id = _ids[i];
      return (id, values[i]);
    }).toList();
  }

  // Ensure sorted by ID:
  valuesByIndexes.sort((a, b) => compare(a.$1, b.$1));

  return valuesByIndexes;
}