Type: Validation

class data.validation.Validation
type Validation(α, β) = Failure(α) | Success(β)

implements
  Applicative(β), Functor(β), ToString

Represents the logical disjunction between α and β.

Comparing and testing

#isFailure

Validation.prototype.isFailure
Boolean

True if the Validation(α, β) contains a Failure value.

#isSuccess

Validation.prototype.isSuccess
Boolean

True if the Validation(α, β) contains a Success value.

#isEqual()

Validation.prototype.isEqual(aValidation)
@Validation(α, β) => Validation(α, β) → Boolean

Tests if two Validation(α, β) structures are equal. Compares the contents using reference equality.

Constructing

.Failure()

static Validation.Failure(value)
α → Validation(α, β)

Constructs a new Validation structure holding a Failure value.

.Success()

static Validation.Success(value)
β → Validation(α, β)

Constructs a new Validation structure holding a Success value.

.of()

static Validation.of(value)
β → Validation(α, β)

Creates a new Validation instance holding the Success value β.

.fromNullable()

static Validation.fromNullable(value)
α | null | undefined → Validation(null | undefined, α)

Constructs a new Validation structure from a nullable type.

Takes the Failure value if the value is null or undefined. Takes the Success case otherwise.

.fromEither()

static Validation.fromEither(value)
Either(α, β) → Validation(α, β)

Constructs a new Validation(α, β) structure from an Either(α, β) structure.

Converting

#toString()

Validation.prototype.toString()
@Validation(α, β) => Unit → String

Returns a textual representation of the Validation(α, β) structure.

Extracting

#get()

Validation.prototype.get()
Raises:
  • TypeError - If the structure has no Success value.
@Validation(α, β) => Unit → β :: throws

Extracts the Success value out of the Validation(α, β) structure, if it exists.

#getOrElse()

Validation.prototype.getOrElse(default)
@Validation(α, β) => β → β

Extracts the Success value out of the Validation(α, β) structure. If it doesn’t exist, returns a default value.

#merge()

Validation.prototype.merge()
@Validation(α, β) => Unit → α | β

Returns whichever side of the disjunction that is present.

Transforming

#ap()

Validation.prototype.ap(anApplicative)
@Validation(α, β → γ), f:Applicative(_) => f(β) → f(γ)

Applies the function inside the Validation(α, β) structure to another Applicative type, and combines failures with a semigroup.

#map()

Validation.prototype.map(transformation)
@Validation(α, β) => (β → γ) → Validation(α, γ)

Transforms the Success value of the Validation(α, β) structure using a regular unary function.

#fold()

Validation.prototype.fold(leftTransformation, rightTransformation)
@Validation(α, β) => (α → γ), (β → γ) → γ

Applies a function to each case in the data structure.

#cata()

Validation.prototype.cata(pattern)
@Validation(α, β) => { r | Pattern } → γ
type Pattern {
  Failure: α → γ,
  Success: β → γ
}

Applies a function to each case in the data structure.

#swap()

Validation.prototype.swap()
@Validation(α, β) => Unit → Validation(β, α)

Swaps the disjunction values.

#bimap()

Validation.prototype.bimap(leftTransformation, rightTransformation)
@Validation(α, β) => (α → γ), (β → δ) → Validation(γ, δ)

Maps both sides of the disjunction.

#failureMap()

Validation.prototype.failureMap(transformation)
@Validation(α, β) => (α → γ) → Validation(γ, β)

Maps the left side of the disjunction.

#orElse()

Validation.prototype.orElse(transformation)
@Validation(α, β) => (α → Validation(γ, β)) → Validation(γ, β)

Transforms the Failure value into a new Validation(α, β) structure.