map<RK, RV> method

IMap<RK, RV> map<RK, RV>(
  1. MapEntry<RK, RV> mapper(
    1. K key,
    2. V value
    ), {
  2. bool ifRemove(
    1. RK key,
    2. RV value
    )?,
  3. ConfigMap? config,
})

Returns a new map where all entries of this map are transformed by the given mapper function. However, if ifRemove is provided, the mapped value will first be tested with it and, if ifRemove returns true, the value will be removed from the result map.

Implementation

IMap<RK, RV> map<RK, RV>(
  MapEntry<RK, RV> Function(K key, V value) mapper, {
  bool Function(RK key, RV value)? ifRemove,
  ConfigMap? config,
}) {
  config ??= defaultConfig;
  Map<RK, RV> map = ListMap.fromEntries(
    entries
        .map((entry) => mapper(entry.key, entry.value))
        .where((entry) => ifRemove == null || !ifRemove(entry.key, entry.value)),
    sort: config.sort,
  );

  return IMap._unsafeFromMap(map, config: config);
}