rtfeldman/elm-validate/1.0.4

NOTE: this package is not compatible with Elm 0.19.1

Validate

Convenience functions for validating data.

Validating a subject

type alias Validator error subject =
subject -> List error

A Validator is a function which takes a subject and returns a list of errors describing anything invalid about that subject.

An empty error list means the subject was valid.

ifBlank : error -> Validator error String

Return an error if the given String is empty, or if it contains only whitespace characters.

ifNotInt : error -> Validator error String

Return an error if the given String cannot be parsed as an Int.

ifEmptyDict : error -> Validator error (Dict comparable v)

Return an error if the given Dict is empty.

ifEmptySet : error -> Validator error (Set comparable)

Return an error if the given Set is empty.

ifInvalid : (subject -> Bool) -> error -> Validator error subject

Return an error if the given predicate returns True for the given subject.

Combining validators

all : List (Validator error subject) -> Validator error subject

Run each of the given validators, in order, and return their concatenated error lists.

any : List (Validator error subject) -> subject -> Bool

Return True if none of the given validators returns any errors for the given subject, and False if any validator returns one or more errors.

eager : List (Validator error subject) -> subject -> Maybe error

Run each of the given validators, in order, stopping after the first error and returning it. If no errors are encountered, return Nothing.