elm-community/dict-extra/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Dict.Extra

Convenience functions for working with Dict

List operations

groupBy : (a -> comparable) -> List a -> Dict comparable (List a)

Takes a key-fn and a list, creates a Dict which maps the key returned from key-fn, to a list of matching elements.

mary = {groupId: 1, name: "Mary"}
jack = {groupId: 2, name: "Jack"}
jill = {groupId: 1, name: "Jill"}
groupBy .groupId [mary, jack, jill] == Dict.fromList [(2, [jack]), (1, [mary, jill])]

Manipulation

removeWhen : (comparable -> v -> Bool) -> Dict comparable v -> Dict comparable v

Keep elements which fails to satisfy the predicate. This is functionaly equivalent to Dict.filter (not << predicate) dict.

removeWhen (\c v -> v == 1) Dict.fromList [("Mary", 1), ("Jack", 2), ("Jill", 1)] == Dict.fromList [("Jack", 2)]