the-sett/elm-refine/1.0.0

NOTE: the latest version is 1.4.0

Refined

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.

Definition of Refined types and functions to create them.

type Refined i a e

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.

(i -> Result e a)
-> Decoder i
-> (i -> 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.

Helper functions for working with refined types.

decoder : Refined i a e -> Decoder a

JSON decoder for a refined type.

encoder : Refined i a e -> a -> Value

JSON encoder for 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.

Functions for building refined integers.

Describes the possible errors that can occur when creating a refined integer.

Translates integer errors to descriptive strings.

gt : Int -> Int -> Result IntError Int

Guard function for creating an integer that must be greater than a given value.

lt : Int -> Int -> Result IntError Int

Guard function for creating an integer that must be less than a given value.

Functions for building refined strings.

Describes the possible errors that can occur when creating a refined string.

Translates string errors to descriptive strings.

minLength : Int -> String -> Result StringError String

Guard function for creating a string that must have a given minimum length.

maxLength : 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.