I recently published the pzp1997/assoc-list package, which aims to address the problem that the
Dict module in elm/core does not work with custom keys.
While there are already several packages that attempt to solve this problem, all of the ones I have found store a function for converting the keys to
comparable within the data structure itself. (The downside here is that storing functions in your data can cause runtime errors and makes serialization more challenging.) I decided to approach the problem from a different angle by using a data structure called an association list which only needs keys to be equatable rather than comparable. For better or worse, all types in Elm are equatable, so pretty much any type can be used as a key “right out of the box” in my library.
Intrigued? Check out https://package.elm-lang.org/packages/pzp1997/assoc-list/1.0.0/ for more information! Over there I explain how to use the library (spoiler: it’s a drop-in replacement for elm/core
Dict), performance considerations, and take a deeper look at existing alternatives.
(And as an added bonus, you can also use the library as an ordered dictionary!)