the-sett / elm-refine / Enum

Enum provides support for various different ways of defining an enum in Elm.

Definition of Enums and functions to create them.


type Enum a

An enum is a list of possible values and a function for turning an instance of one into a string.

define : List a -> (a -> String) -> Enum a

Creates an enum definition from a list of possible values and a definition opf the toString function.

build : Enum a -> String -> Maybe a

Looks up an instance of an enum from its string representation.

Helper functions for working with Enums.

decoder : Enum a -> Json.Decode.Decoder a

JSON Decoder for an enum

encoder : Enum a -> a -> Json.Encode.Value

JSON Encoder for an enum.

toString : Enum a -> a -> String

Turns an instance of an enum into a string.

Dicts over enum keys.

emptyDict : Enum k -> Dict k v

Creates an empty dict with an Enum key.

singletonDict : Enum k -> k -> v -> Dict k v

Creates a dict with a single entry with an Enum key.

dictDecoder : Enum k -> Json.Decode.Decoder v -> Json.Decode.Decoder (Dict k v)

Creates a decoder for dictionaries with enum values as keys.

dictEncoder : Enum k -> (v -> Json.Encode.Value) -> Dict k v -> Json.Encode.Value

Creates an encoder for dictionaries with enum values as keys.

stringDict : Enum k -> (v -> a) -> Dict k v -> Dict String a

Turns a Dict with enum keys, into a normal Dict with the enum keys as strings.