Ludwig.Validation

Module Members

addPrefix

(Function)

Add a prefix to the error message. In case this is a successful validation, we don’t do anything.

Type Signature

 fun (String, Validation) -> Validation
Argument: prefix
Type: String
Argument: val
Type: Validation
Returns:
Type: Validation

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

getFailureMessage

(Function)

Get the failure message. If the validation is a success, this will return the empty string.

Type Signature

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

isFailure

(Function)

Check if a validation failed.

Type Signature

 fun (Validation) -> Bool
Argument: val
Type: Validation
Returns:
Type: Bool

isSuccess

(Function)

Check if a validation was successful.

Type Signature

 fun (Validation) -> Bool
Argument: val
Type: Validation
Returns:
Type: Bool

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

optional

(Function)

Apply a validation on an optional. If there is no value, the ‘Validation’ is successfull.

Type Signature

 fun (fun (a) -> Validation, Optional<a>) -> Validation
Argument: f
Type: fun ( a) -> Validation
Argument: x
Type: Optional<a>
Returns:
Type: Validation

toErrorAt

(Function)

Convert the validation to an error using errorAt (if there is any). If the validation is successful, just return the unit ().

Type Signature

 fun (Int, Validation) -> 0-tuple
Argument: n
Type: Int
Argument: val
Type: Validation
Returns:
Type: 0-tuple

Validation

(Type)

type Validation:
  | Success
  | Failure String

Failure

(Constructor)

Argument:
Ludwig.String

Success

(Constructor)

The validation type.

DEPRECATED: The constructors of this type should not be used directly. Use success or failure instead.

success

(Value)

Validation success:
  Success

Return a ‘Success’ value

Type Signature

 Validation