filter method

Map<K, V> filter(
  1. bool predicate(
    1. K key,
    2. V value
    )
)

Returns a new map with all entries that satisfy the given predicate. The entries in the resulting map preserve the order of the original map.

Implementation

Map<K, V> filter(bool Function(K key, V value) predicate) {
  if (isNullOrEmpty) return {};
  final map = <K, V>{};
  for (final key in this!.keys) {
    if (predicate(key, this?[key] as V)) {
      map[key] = this?[key] as V;
    }
  }
  return map;
}