object

# `validation`

Constructors for validation terms. A validation term is either `valid(Value)` or `invalid(Errors)` where `Errors` is a list of errors. Validation terms allow applicative-style error accumulation.

Availability:
`logtalk_load(validations(loader))`
Author: Paulo Moura
Version: 1:0:1
Date: 2026-04-22
Compilation flags:
`static, context_switching_calls`
Provides:
type::type/1
type::check/2
Uses:
type
Remarks:

> - Type-checking support: Defines a `validation` type for use with the `type` library object.

Inherited public predicates:
(none)

## Public predicates

### `of_valid/2`

Constructs a validation term holding a valid value.

Compilation flags:
`static`
Template:
`of_valid(Value,Validation)`
Mode and number of proofs:
`of_valid(@term,--nonvar)` - `one`

### `of_invalid/2`

Constructs a validation term holding a single error.

Compilation flags:
`static`
Template:
`of_invalid(Error,Validation)`
Mode and number of proofs:
`of_invalid(@term,--nonvar)` - `one`

### `of_invalids/2`

Constructs a validation term holding a list of errors.

Compilation flags:
`static`
Template:
`of_invalids(Errors,Validation)`
Mode and number of proofs:
`of_invalids(@list,--nonvar)` - `one`

### `from_goal/4`

Constructs a validation term holding a value bound by calling the given goal. Otherwise returns a validation term with a single error represented by the `Error` argument.

Compilation flags:
`static`
Template:
`from_goal(Goal,Value,Error,Validation)`
Meta-predicate template:
`from_goal(0,*,*,*)`
Mode and number of proofs:
`from_goal(+callable,--term,@term,--nonvar)` - `one`

### `from_goal/3`

Constructs a validation term holding a value bound by calling the given goal. Otherwise returns a validation term with a single error being the goal error or the atom `fail` representing goal failure.

Compilation flags:
`static`
Template:
`from_goal(Goal,Value,Validation)`
Meta-predicate template:
`from_goal(0,*,*)`
Mode and number of proofs:
`from_goal(+callable,--term,--nonvar)` - `one`

### `from_goal/2`

Constructs a validation term holding a value bound by calling the given closure. Otherwise returns a validation term with a single error being the closure error or the atom `fail` representing closure failure.

Compilation flags:
`static`
Template:
`from_goal(Closure,Validation)`
Meta-predicate template:
`from_goal(1,*)`
Mode and number of proofs:
`from_goal(+callable,--nonvar)` - `one`

### `from_generator/4`

Constructs validation terms with the values generated by calling the given goal. On goal error or failure, returns a validation term with a single error represented by the `Error` argument.

Compilation flags:
`static`
Template:
`from_generator(Goal,Value,Error,Validation)`
Meta-predicate template:
`from_generator(0,*,*,*)`
Mode and number of proofs:
`from_generator(+callable,--term,@term,--nonvar)` - `one_or_more`

### `from_generator/3`

Constructs validation terms with the values generated by calling the given goal. On goal error or failure, returns a validation term with, respectively, a single error being the goal error or the atom `fail` representing goal failure.

Compilation flags:
`static`
Template:
`from_generator(Goal,Value,Validation)`
Meta-predicate template:
`from_generator(0,*,*)`
Mode and number of proofs:
`from_generator(+callable,--term,--nonvar)` - `one_or_more`

### `from_generator/2`

Constructs validation terms with the values generated by calling the given closure. On closure error or failure, returns a validation term with, respectively, a single error being the closure error or the atom `fail` representing closure failure.

Compilation flags:
`static`
Template:
`from_generator(Closure,Validation)`
Meta-predicate template:
`from_generator(1,*)`
Mode and number of proofs:
`from_generator(+callable,--nonvar)` - `one_or_more`

### `from_optional/3`

Converts an optional term to a validation term. Returns a valid term holding the value if the optional term is not empty. Returns an invalid term with the given error otherwise.

Compilation flags:
`static`
Template:
`from_optional(Optional,Error,Validation)`
Mode and number of proofs:
`from_optional(+nonvar,@term,--nonvar)` - `one`

### `from_expected/2`

Converts an expected term to a validation term. Returns a valid term holding the value if the expected term holds a value. Returns an invalid term with the expected term error otherwise.

Compilation flags:
`static`
Template:
`from_expected(Expected,Validation)`
Mode and number of proofs:
`from_expected(+nonvar,--nonvar)` - `one`

## Protected predicates

(no local declarations; see entity ancestors if any)

## Private predicates

(no local declarations; see entity ancestors if any)

## Operators

(none)

See also

validation(Validation), validated, type, arbitrary