Did you know ... Search Documentation:
Pack maybe -- prolog/maybe.pl
PublicShow source
 is_just(+Maybe:maybe) is semidet
True if Maybe is just(_). Useful for include/3.
 is_nothing(+Maybe:maybe) is semidet
True if Maybe is nothing. Useful for exclude/3.
 just_value(+Just:maybe(T), -Value:T) is det
just_value(-Just:maybe(T), +Value:T) is det
True if Just wraps Value. Throws an exception if Just is nothing.
 maybe_value(+Maybe:maybe(T), -Value:T) is det
True if Maybe is just(Value); fails for nothing.
 call_maybe(:Goal, ?Value:T, -Maybe:maybe(T)) is multi
If call(Goal) succeeds, Maybe=just(Value), otherwise Maybe=nothing. Goal typically binds Value. If Goal produces multiple solutions on backtracking, so will call_maybe/3. In that case, Maybe will never be nothing.

For example,

?- L = [a,b,c], call_maybe(L=[H|_], H, MaybeHead).
H = a,
MaybeHead = just(a).

?- L = [], call_maybe(L=[H|_], H, MaybeHead).
MaybeHead = nothing.

Of course, that particular example could have been implemented with maybe_list/2 instead.

 maybe_list(?Maybe:maybe(T), ?List:list(T)) is det
Relates a List to a Maybe value. An empty list is equivalent to nothing. A non-empty list is equivalent to just(Head).
 maybe_default_value(+Maybe:maybe(T), +Default:T, -Value:T) is det
maybe_default_value(-Maybe:maybe(T), +Default:T, +Value:T) is multi
True if Maybe wraps Value with a Default for the nothing case.
 default_maybe_value(+Default:T, +Maybe:maybe(T), -Value:T) is det
default_maybe_value(+Default:T, -Maybe:maybe(T), +Value:T) is multi
Like maybe_default_value/3 with different argument order. This argument order is convenient for maplist/3 like so:
maplist(default_maybe_value(7), Maybes, DefaultedValues).
 map_maybe(+Goal, ?Maybe0:maybe, ?Maybe:maybe)
True if call(Goal, Value0, Value) succeeds for just values. Goal is not called for nothing values, which remain unchanged. "Use the source" for a clearer explanation.
 fold_maybe(+Goal, ?Maybe:maybe, ?Accum0, ?Accum)
nothing leaves Accum0=Accum while just relates them via Goal. "Use the source" for a clearer explanation.