miniBill / elm-generic-dict / GenericDict

This module can be use to codegen a dictionary with a custom type as key.

Types


type Config

Configuration used to build a generic dictionary.

Configuration

init : { keyType : Elm.Annotation.Annotation, namespace : List String, toComparable : Elm.Expression -> Elm.Expression } -> Config

Starts building a custom dictionary, given the type of the key, the namespace of the resulting file, and a toComparable function.

The toComparable function will be copied in each declaration, so it should be kept very simple (or extracted to a function, and then passed in like { toComparable = Gen.YourType.toString }, or similar).

withTypeName : String -> Config -> Config

Use a custom type name for the dictionary type.

useElmFastDict : Config -> Config

Use miniBill/elm-fast-dict as the backing container. This means that generated code will depend on that package but gives the advantages of that package (read elm-fast-dict's README for pros and cons).

Generation

generateFile : Config -> Elm.File

Generates a file from the given configuration.

generateDeclarations : Config -> List Elm.Declaration

Generates declarations from the given configuration.

This can be useful if you want to add your own custom declarations to the file.