Ludwig.Validation

Module Members

and

(Function)

Combine two validations, ensuring that they both pass.

Example:

valid:    and(success, success)           # => success
invalid1: and(failure("A"), success)      # => failure("A")
invalid2: and(success, failure("B"))      # => failure("B")
invalid3: and(failure("A"), failure("B")) # => failure("A")

Type Signature

 fun (Validation, Validation) -> Validation
Argument: x
Type: Validation
Argument: y
Type: Validation
Returns:
Type: Validation

assert

(Function)

Create a ‘Validation’ from a ‘Bool’ value.

Type Signature

 fun (String, Bool) -> Validation
Argument: err
Type: String
Argument: test
Type: Bool
Returns:
Type: Validation

failure

(Function)

Raise a validation failure.

Type Signature

 fun (String) -> Validation
Argument: err
Type: String
Returns:
Type: Validation

join

(Function)

Reduce a list of Validations into a single value.

Example usage:

invalid1: join([Success, Success, Failure("boom"), Success]) # => Failure("boom")
invalid2: join([Failure("A"), Failure("B")])                 # => Failure("A")
valid: join([Success, Success])                              # => Success

Type Signature

 fun (List<Validation>) -> Validation
Argument: validations

The list of validations to combine.

Type: List<Validation>

Returns:

A single validation that is the result of anding all of the supplied validations together.

Type: Validation

Validation

(Type)

type Validation:
  | Success
  | Failure String

Failure

(Constructor)

Argument:
Ludwig.String

Success

(Constructor)

success

(Value)

Validation success:
  Success

Return a ‘Success’ value

Type Signature

 Validation