object
optional(Optional)
ï
Optional term handling predicates. Requires passing an optional term (constructed using the optional
object predicates) as a parameter.
logtalk_load(optionals(loader))
static, context_switching_calls
Public predicatesï
is_empty/0
ï
True if the optional term is empty. See also the if_empty/1
predicate.
static
is_empty
- zero_or_one
is_present/0
ï
True if the optional term holds a value. See also the if_present/1
predicate.
static
is_present
- zero_or_one
if_empty/1
ï
Calls a goal if the optional term is empty. Succeeds otherwise.
static
if_empty(Goal)
if_empty(0)
if_empty(+callable)
- zero_or_more
if_present/1
ï
Applies a closure to the value hold by the optional term if not empty. Succeeds otherwise.
static
if_present(Closure)
if_present(1)
if_present(+callable)
- zero_or_more
if_present_or_else/2
ï
Applies a closure to the value hold by the optional term if not empty. Otherwise calls the given goal.
static
if_present_or_else(Closure,Goal)
if_present_or_else(1,0)
if_present_or_else(+callable,+callable)
- zero_or_more
filter/2
ï
Returns the optional term when it is not empty and the value it holds satisfies a closure. Otherwise returns an empty optional term.
static
filter(Closure,NewOptional)
filter(1,*)
filter(+callable,--nonvar)
- one
map/2
ï
When the optional term is not empty and mapping a closure with the value it holds and the new value as additional arguments is successful, returns an optional term with the new value. Otherwise returns an empty optional term.
static
map(Closure,NewOptional)
map(2,*)
map(+callable,--nonvar)
- one
flat_map/2
ï
When the optional term is not empty and mapping a closure with the value it holds and the new optional term as additional arguments is successful, returns the new optional term. Otherwise returns an empty optional term.
static
flat_map(Closure,NewOptional)
flat_map(2,*)
flat_map(+callable,--nonvar)
- one
or/2
ï
Returns the same optional term if not empty. Otherwise calls closure to generate a new optional term. Fails if optional term is empty and calling the closure fails or throws an error.
static
or(NewOptional,Closure)
or(*,1)
or(--term,@callable)
- zero_or_one
get/1
ï
Returns the value hold by the optional term if not empty. Throws an error otherwise.
static
get(Value)
get(--term)
- one_or_error
existence_error(optional_term,Optional)
or_else/2
ï
Returns the value hold by the optional term if not empty or the given default value if the optional term is empty.
static
or_else(Value,Default)
or_else(--term,@term)
- one
or_else_get/2
ï
Returns the value hold by the optional term if not empty. Applies a closure to compute the value otherwise. Throws an error when the optional term is empty and the value cannot be computed.
static
or_else_get(Value,Closure)
or_else_get(*,1)
or_else_get(--term,+callable)
- one_or_error
existence_error(optional_term,Optional)
or_else_call/2
ï
Returns the value hold by the optional term if not empty or calls a goal deterministically if the optional term is empty.
static
or_else_call(Value,Goal)
or_else_call(*,0)
or_else_call(--term,+callable)
- zero_or_one
or_else_fail/1
ï
Returns the value hold by the optional term if not empty. Fails otherwise. Usually called to skip over empty optional terms.
static
or_else_fail(Value)
or_else_fail(--term)
- zero_or_one
or_else_throw/2
ï
Returns the value hold by the optional term if not empty. Throws the given error otherwise.
static
or_else_throw(Value,Error)
or_else_throw(--term,@nonvar)
- one_or_error
Protected predicatesï
(none)
Private predicatesï
(none)
Operatorsï
(none)
See also