elm-generic-dict elm-generic-dict can be used to codegen dictionaries with arbitrary types as keys. It is meant to be used as a library with elm-codegen.
The dictionaries don't contain functions, and the API (of the generated code) doesn't require you to pass any function.
The main disadvantage of using this approach is code duplication, while the advantages are:
Say you'd like a Dict of UUID.UUID:
codegen/Generate.elm to look something likemodule Generate exposing (main)
import Elm
import Elm.Annotation as Type
import Gen.CodeGen.Generate as Generate
import Gen.UUID
import GenericDict
main : Program {} () ()
main =
Generate.run
[ customDictFile
]
customDictFile : Elm.File
customDictFile =
GenericDict.init
{ keyType = Gen.UUID.annotation_.uUID
, namespace = []
, toComparable = Gen.UUID.toString
}
|> GenericDict.withTypeName "UuidDict"
|> GenericDict.generateFileelm-codegen run to have it create the generated/UuidDict.elmelm.json to include generated/ as a source-directoryImport UuidDict exposing (UuidDict) to use it like a UuidDict a