Refined provides support for common ways of creating refined types in Elm. A refined type is a basic type like Int or String, that has a constructor which ensures that it can only take on certain values. The basic type is wrapped in a custom type which is made opaque - so that only instances of it with the allowable values can ever be created.
Refined types.
i
is the underlying basic type.
a
is the refined custom type that will be created
from it.
e
is the type or errors that the constructor can return when invalid inputs
are given.
define : (i -> Result e a) -> Json.Decode.Decoder i -> (i -> Json.Encode.Value) -> (e -> String) -> (a -> i) -> Refined i a e
Creates a refined type from the input guard function, decoder on the underlying basic type, encoder on the underlying basic type, the error to string function, and the unboxing function that extracts the underlying basic type.
build : Refined i a e -> i -> Result e a
Builds an instance of a refined type from its input type.
errorToString : Refined i a e -> e -> String
Prints the error messages resulting from failing to create an instance of a refined type.
decoder : Refined i a e -> Json.Decode.Decoder a
JSON decoder for a refined type.
encoder : Refined i a e -> a -> Json.Encode.Value
JSON encoder for a refined type.
unbox : Refined i a e -> a -> i
Unboxes an instance of a refined type.
emptyDict : Refined comparable k e -> Dict comparable k v
Creates an empty dict with a Refined
key.
singletonDict : Refined comparable k e -> k -> v -> Dict comparable k v
Creates a dict with a single entry with a Refined
key.
dictDecoder : Refined comparable k e -> Json.Decode.Decoder v -> Json.Decode.Decoder (Dict comparable k v)
Creates a decoder for dictionaries with refined values as keys.
dictEncoder : Refined comparable k e -> (v -> Json.Encode.Value) -> Dict comparable k v -> Json.Encode.Value
Creates an encoder for dictionaries with refined values as keys.
unboxedDict : Refined comparable k e -> (v -> a) -> Dict comparable k v -> Dict comparable a
Turns a Dict with refined keys, into a normal Dict with the refined keys unboxed to their underlying type.
Describes the possible errors that can occur when creating a refined integer.
intErrorToString : IntError -> String
Translates integer errors to descriptive strings.
gt : Basics.Int -> Basics.Int -> Result IntError Basics.Int
Guard function for creating an integer that must be greater than a given value.
gte : Basics.Int -> Basics.Int -> Result IntError Basics.Int
Guard function for creating an integer that must be greater than or equal to a given value.
lt : Basics.Int -> Basics.Int -> Result IntError Basics.Int
Guard function for creating an integer that must be less than a given value.
lte : Basics.Int -> Basics.Int -> Result IntError Basics.Int
Guard function for creating an integer that must be less than or equal to a given value.
Describes the possible errors that can occur when creating a refined string.
stringErrorToString : StringError -> String
Translates string errors to descriptive strings.
minLength : Basics.Int -> String -> Result StringError String
Guard function for creating a string that must have a given minimum length.
maxLength : Basics.Int -> String -> Result StringError String
Guard function for creating a string that must have a given maximum length.
regexMatch : String -> String -> Result StringError String
Guard function for creating a string that must match a given regular expression.