object

expected(Expected)

Expected term predicates. Requires passing an expected term (constructed using the expected object predicates) as a parameter.

Author: Paulo Moura
Version: 1.3
Date: 2019/11/26
Compilation flags:
static, context_switching_calls
Dependencies:
(none)
Remarks:
(none)
Inherited public predicates:
(none)

Public predicates

is_unexpected/0

True if the expected term holds an error. See also the if_unexpected/1 predicate.

Compilation flags:
static
Mode and number of proofs:
is_unexpected - zero_or_one

is_expected/0

True if the expected term holds a value. See also the if_expected/1 predicate.

Compilation flags:
static
Mode and number of proofs:
is_expected - zero_or_one

if_unexpected/1

Applies a closure when the expected term holds an error using the error as argument. Succeeds otherwise. Can be used to throw the exception hold by the expected term by calling it the atom throw.

Compilation flags:
static
Template:
if_unexpected(Closure)
Meta-predicate template:
if_unexpected(1)
Mode and number of proofs:
if_unexpected(+callable) - zero_or_more

if_expected/1

Applies a closure when the expected term holds a value using the value as argument. Succeeds otherwise.

Compilation flags:
static
Template:
if_expected(Closure)
Meta-predicate template:
if_expected(1)
Mode and number of proofs:
if_expected(+callable) - zero_or_more

unexpected/1

Returns the error hold by the expected term. Throws an error otherwise.

Compilation flags:
static
Template:
unexpected(Error)
Mode and number of proofs:
unexpected(--term) - one_or_error
Exceptions:
Reference holds a value:
existence_error(unexpected_term,Expected)

expected/1

Returns the value hold by the expected term. Throws an error otherwise.

Compilation flags:
static
Template:
expected(Value)
Mode and number of proofs:
expected(--term) - one_or_error
Exceptions:
Reference holds an error:
existence_error(expected_term,Expected)

map/2

When the expected term does not hold an error and mapping a closure with the expected value and the new value as additional arguments is successful, returns a reference with the new value. Otherwise returns the same expected term.

Compilation flags:
static
Template:
map(Closure,NewExpected)
Meta-predicate template:
map(2,*)
Mode and number of proofs:
map(+callable,--nonvar) - one

flat_map/2

When the expected term does not hold an error and mapping a closure with the expected value and the new expected term as additional arguments is successful, returns the new expected term. Otherwise returns the same expected term.

Compilation flags:
static
Template:
flat_map(Closure,NewExpected)
Meta-predicate template:
flat_map(2,*)
Mode and number of proofs:
flat_map(+callable,--nonvar) - one

or_else/2

Returns the value hold by the expected term if it does not hold an error or the given default term if the expected term holds an error.

Compilation flags:
static
Template:
or_else(Value,Default)
Mode and number of proofs:
or_else(--term,@term) - one

or_else_get/2

Returns the value hold by the expected term if it does not hold an error. Otherwise applies a closure to compute the expected value. Throws an error when the expected term holds an error and a value cannot be computed.

Compilation flags:
static
Template:
or_else_get(Value,Closure)
Meta-predicate template:
or_else_get(*,1)
Mode and number of proofs:
or_else_get(--term,+callable) - one_or_error
Exceptions:
Reference holds an unexpected term and an expected term cannot be computed:
existence_error(expected_term,Expected)

or_else_call/2

Returns the value hold by the expected term if it does not hold an error. Calls a goal deterministically otherwise.

Compilation flags:
static
Template:
or_else_call(Value,Goal)
Meta-predicate template:
or_else_call(*,0)
Mode and number of proofs:
or_else_call(--term,+callable) - zero_or_one

or_else_throw/1

Returns the value hold by the expected term if present. Throws the error hold by the expected term as an exception otherwise.

Compilation flags:
static
Template:
or_else_throw(Value)
Mode and number of proofs:
or_else_throw(--term) - one_or_error

or_else_fail/1

Returns the value hold by the expected term if it does not hold an error. Fails otherwise. Usually called to skip over expected terms holding errors.

Compilation flags:
static
Template:
or_else_fail(Value)
Mode and number of proofs:
or_else_fail(--term) - zero_or_one

Operators

(none)

See also

expected