object
optional(Reference)
¶
Optional reference predicates. Requires passing a reference constructed using the “optional” object as a parameter.
static, context_switching_calls
(no dependencies on other entities)
Public interface¶
is_empty/0
¶
True if the reference is empty. Avoid whenever possible by using instead the if_empty/1 predicate.
static
is_empty
- zero_or_one
is_present/0
¶
True if the reference holds a term. Avoid whenever possible by using instead the if_present/1 predicate.
static
is_present
- zero_or_one
if_empty/1
¶
Calls a goal if the reference is empty. Succeeds otherwise.
static
if_empty(Goal)
if_empty(0)
if_empty(+callable)
- zero_or_more
if_present/1
¶
Applies a closure if the reference holds a term using the term as additional argument. Succeeds otherwise.
static
if_present(Closure)
if_present(1)
if_present(+callable)
- zero_or_more
filter/2
¶
Returns the reference when it is non-empty and the term it holds satisfies a closure. Otherwise returns an empty reference.
static
filter(Closure,Reference)
filter(1,*)
filter(+callable,--nonvar)
- one
map/2
¶
When the reference is non-empty and mapping a closure with the term it holds and the new term as additional arguments is successful, returns a reference with the new term. Otherwise returns an empty reference.
static
map(Closure,NewReference)
map(2,*)
map(+callable,--nonvar)
- one
flat_map/2
¶
When the reference is non-empty and mapping a closure with the optional tern and the new reference as additional arguments is successful, returns the new reference. Otherwise returns an empty reference.
static
flat_map(Closure,NewReference)
flat_map(2,*)
flat_map(+callable,--nonvar)
- one
get/1
¶
Returns the term hold by the reference if not empty. Throws an error otherwise.
static
get(Term)
get(--term)
- one_or_error
existence_error(optional_term,Reference)
or_else/2
¶
Returns the term hold by the reference if not empty or the given default term if the reference is empty.
static
or_else(Term,Default)
or_else(--term,@term)
- one
or_else_get/2
¶
Returns the term hold by the reference if not empty. Applies a closure to compute the term otherwise. Throws an error when the reference is empty and the term cannot be computed.
static
or_else_get(Term,Closure)
or_else_get(*,1)
or_else_get(--term,+callable)
- one_or_error
existence_error(optional_term,Reference)
or_else_call/2
¶
Returns the term hold by the reference if not empty or calls a goal deterministically if the reference is empty. Can be used e.g. to generate an exception for empty optionals.
static
or_else_call(Term,Goal)
or_else_call(*,0)
or_else_call(--term,+callable)
- zero_or_one
or_else_fail/1
¶
Returns the term hold by the reference if not empty. Fails otherwise. Usually called to skip over empty references.
static
or_else_fail(Term)
or_else_fail(--term)
- zero_or_one
Protected interface¶
(none)
Private predicates¶
(none)
Operators¶
(none)