partition<K, V> method

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

Split map into two maps based on the predicate. Returns a list of two maps.

Implementation

Pair<Map<K, V>, Map<K, V>> partition<K, V>(
    bool Function(K key, V value) predicate) {
  final map1 = <K, V>{};
  final map2 = <K, V>{};
  for (final key in keys) {
    if (predicate(key as K, this[key] as V)) {
      map1[key] = this[key] as V;
    } else {
      map2[key] = this[key] as V;
    }
  }
  return Pair(map1, map2);
}