update method
Updates the set
for the provided key
.
If the key is present, invokes update with the current set
and stores
the new set in the map.
If the key is not present and ifAbsent
is provided, calls ifAbsent
and adds the key with the returned set
to the map.
If the key is not present and ifAbsent
is not provided, return the original map
without modification. Note: If you want ifAbsent
to throw an error, pass it like
this: ifAbsent: () => throw ArgumentError();
.
If you want to get the original set before the update, you can provide the
previousSet
parameter.
Implementation
@useCopy
IMapOfSets<K, V> update(
K key,
ISet<V> Function(ISet<V> set) update, {
ISet<V> Function()? ifAbsent,
Output<ISet<V>>? previousSet,
}) {
bool Function(K key, ISet<V> set)? ifRemove;
if (config.removeEmptySets) ifRemove = (K key, ISet<V> set) => set.isEmpty;
return IMapOfSets<K, V>._unsafe(
_mapOfSets.update(
key,
update,
ifAbsent: ifAbsent,
ifRemove: ifRemove,
previousValue: previousSet,
),
config);
}