Extensions to the core Dict
library.
indexBy : (v -> comparable) -> List v -> Dict comparable v
Turn a list of items into an indexed dictionary.
Supply an indexing function (eg. .id
) and a list of
items. indexBy
returns a dictionary with each item stored under
its index.
This code assumes each index is unique. If that is not the case, you
should use groupBy
instead.
groupBy : (v -> comparable) -> List v -> Dict comparable (List v)
Group a list of items by a key.
Supply an indexing function (eg. .id
) and a list of
items. groupBy
returns a dictionary of group-key/list-of-items.
If the indexing function returns a unique key for every item, consider indexBy
instead.
frequency : List comparable -> Dict comparable Basics.Int
Create a frequency-map from the given list.
getWithDefault : a -> comparable -> Dict comparable a -> a
Attempt to find a key, if it's not there, return a default value.
foldToList : (comparable -> v -> b) -> Dict comparable v -> List b
Run a function over the dictionary entries, resulting in a list of the final results.
updateDict : (a -> ( a, Platform.Cmd.Cmd cmd )) -> comparable -> Dict comparable a -> ( Dict comparable a, Platform.Cmd.Cmd cmd )
Apply an Elm update function - Model -> (Model, Cmd Msg)
- to a Dict
entry, if present.
It's quite common in Elm to want to run a model-update function, over some dictionary of models, but only if that model is available.
This function makes it more convenient to reach inside a Dict
and
apply an update. If the data is not there, the Dict
is returned
unchanged with a Cmd.none
.