Two implementations of a bag using a dict and an association list
{-| type of List.Bag -}
type alias Bag a =
List (a, Int)
{-| type of Bag -}
type alias Bag comparable a =
{ content : Dict comparable ( a, Int )
, encode : a -> comparable
}elm install Orasund/elm-bagYou should use the list implementation if
else use the dict implementation
I did a few performance test and can say that the list implementation always behaved worse then using a dict.
For a smaller amount of keys the different is however not noticeable (at around 50 keys the association list needs roughly double the amount of time to insert or count elements compared to a dict.)
I would assume that for <10 keys you will not notice a difference.
Only alternative so far has been JohnBugner/elm-bag, which I used as a clear inspiration to this package. While JohnBugner used a normal dictionary, i used the same approach as the AnyDict implementation by turboMaCk.
I want to give credit to both JohnBugner and TurboMaCk for their contribution to the elm community. This package is just the combination of the previous works of both of them.