update : Dict(k, v), k, (Try(v, [Missing]) -> Try(v, [Missing])) -> Dict(k, v) where [k.is_eq : k, k -> Bool, k.to_hash : k, Hasher -> Hasher]
Insert, update or remove a value for a specified key. This is more efficient
than doing a Dict.get and then a Dict.insert call.
The provided function receives:
- Ok(value) if the key is currently in the dictionary.
- Err(Missing) if the key is not currently in the dictionary.
It should return:
- Ok(new_value) to insert or update the value at the key.
- Err(Missing) to remove the key (or leave it absent).
alter = |possible_value| match possible_value {
Err(Missing) => Ok(Bool.False)
Ok(value) => if value Err(Missing) else Ok(Bool.True)
}
expect Dict.is_eq(
Dict.update(Dict.empty(), "a", alter),
Dict.single("a", Bool.False),
)