Module validation

Validation with accumulating failures.

Remarks

Validation<E, T> is a type that represents a state of accumulated failure or success. It is represented by two variants: Err<E> and Ok<T>.

  • An Err<E> is a failed Validation and contains a failure of type E.
  • An Ok<T> is a successful Validation and contains a success of type T.

The companion Validation:namespace namespace provides utilities for working with the Validation<E, T> type.

Validation is useful for collecting information about all failures in a program rather than halting evaluation on the first failure. This behavior makes Validation a suitable type for validating data from inputs, forms, and other sources.

Most combinators for Validation begin accumulating failures on the first failed Validation. Combinators with this behavior require a Semigroup implementation from the accumulating failures.

Using Validation with promises

AsyncValidation<E, T> is an alias for Promise<Validation<E, T>>. The companion AsyncValidation:namespace namespace provides utilities for working with the AsyncValidation<E, T> type.

To accommodate promise-like values, this module also provides the AsyncValidationLike<E, T> type as an alias for PromiseLike<Validation<E, T>>.

Importing from this module

The types and namespaces from this module can be imported under the same aliases:

import { AsyncValidation, Validation } from "@neotype/prelude/validation.js";

Or, the types and namespaces can be imported and aliased separately:

import {
type AsyncValidation,
type Validation,
AsyncValidation as AV,
Validation as V
} from "@neotype/prelude/validation.js";

Index

Namespaces

Type Aliases

Generated using TypeDoc