filterWithKeyAndIndex method

Map<K, V> filterWithKeyAndIndex(
  1. bool predicate(
    1. K key,
    2. V value,
    3. int index
    )
)

Returns the list of those elements of the Map whose key/value satisfies predicate.

Implementation

Map<K, V> filterWithKeyAndIndex(
    bool Function(K key, V value, int index) predicate) {
  final entries = this.entries;
  final filteredMap = <K, V>{};
  var i = 0;
  for (final item in entries) {
    if (predicate(item.key, item.value, i)) {
      filteredMap.addEntries([item]);
    }
    i += 1;
  }
  return filteredMap;
}