evancz/Elm — pull request #393 by maxsnew (2013-12-19 04:17:22+00:00)
Title: Add efficient update function for Dict

I needed this for something I'm working on so I implemented in the stdlib.

I don't think this overcomplicates the Dict library at all and it's a pretty common use case that can't be implemented efficiently without accessing the internals of the library so I think it should be in the stdlib instead of an outside library.

This is the type I chose:
`update : comparable -> (Maybe v -> v) -> Dict comparable v -> Dict comparable v`

Alternate types:
`update : comparable -> v -> (v -> v) -> Dict comparable v -> Dict comparable v`
`update : comparable -> (v -> v) -> v -> Dict comparable v -> Dict comparable v`

I like the type I chose because it's pretty obvious from the type what the function does.

And if you want to go with the fully general version:
`update : comparable -> (Maybe v -> Maybe v) -> Dict comparable v -> Dict comparable v`
but that's a more ambitious change that someone else can implement if they want to (it's a generalization of insert and delete).