the-sett / elm-one-many / MultiDict

MultiDict implements a one-to-many relationship, between comparable keys and Sets of values. Each key may be associated with zero or many values, compared with a Dict which associated each key with just one value. Its implementation is a Dict of Sets, but the overhead of creating new sets or removing empty sets as values are added to or removed from the data structyre is managed for you.


type alias MultiDict comparable value comparable1 =
{ vfun : value -> comparable1
, dict : Dict comparable (DictSet comparable1 value) 
}

The type of multi dicts from comparable keys to sets of values.

insert : comparable -> value -> MultiDict comparable value comparable1 -> MultiDict comparable value comparable1

Adds a key-value pair into the dictionary. It is added to the set of values already associated with that key.

remove : comparable -> value -> MultiDict comparable value comparable1 -> MultiDict comparable value comparable1

Removes a key-value pair from the dictionary. It is removed from the set of values associated with the key.

get : comparable -> MultiDict comparable value comparable1 -> Maybe (DictSet comparable1 value)

Gets the set of values associated with a key, or Nothing if there is no set of values.

empty : (value -> comparable1) -> MultiDict comparable value comparable1

Creates an empty multi-dict.