wittjosiah / elm-ordered-dict / OrderedDict

A dictionary mapping unique keys to values preserving insert order.

Dictionaries


type alias OrderedDict k v =
{ order : List k
, dict : Dict k v 
}

A dictionary of keys and values with order.

Build

empty : OrderedDict k v

Create an empty ordered dictionary.

singleton : comparable -> v -> OrderedDict comparable v

Create an ordered dictionary with one key-value pair.

insert : comparable -> v -> OrderedDict comparable v -> OrderedDict comparable v

Insert a key-value pair into an ordered dictionary. Replaces value when there is a collision.

insertAt : Basics.Int -> comparable -> v -> OrderedDict comparable v -> OrderedDict comparable v

Insert a key-value pair into a specific location in the order of an ordered dictionary. Replaces value when there is a collision.

update : comparable -> (Maybe v -> Maybe v) -> OrderedDict comparable v -> OrderedDict comparable v

Update the value of an ordered dictionary for a specific key with a given function.

remove : comparable -> OrderedDict comparable v -> OrderedDict comparable v

Remove a key-value pair from an ordered dictionary. If the key is not found, no changes are made.

Lists

orderedValues : OrderedDict comparable v -> List v

Return a list of items based on their order

empty
    |> insert 33 "Hello"
    |> insert 45 "World"
    |> insertAt 1 39 "Elm"
    |> toList
    == [ "Hello", "Elm", "World" ]