Closed gampleman closed 2 months ago
(Considering how update
is implemented, this should be implemented via get
/if
/insert
and not update (Maybe.map)
)
Also, we could add Dict.Extra.upsert : comparable -> a -> (a -> a) -> Dict comparable a -> Dict comparable a
which also would deal neatly with a very common usage pattern.
(I don't think I've ever used Dict.update
with returning Nothing
if the key was found)
Dict.Extra.updateIfExists : comparable -> (a -> a) -> Dict comparable a -> Dict comparable a
Updates a value if the key is present in the dictionary, leaves the dictionary untouched otherwise.
Motivating use case
Dict.update has an overly complex signature for many use cases. It's fairly common to combine it with
Maybe.map
, but this adds a fair amount of noise in code.