Maybe
=
(λ [(Ref (Maybe a)), (Ref (Maybe a))] Bool)
(= a b)
equality is defined as the equality of both the constructor and the contained value, i.e. (Just 1)
and (Just 1)
are the same, but (Just 1)
and (Just 2)
are not.
apply
(λ [(Maybe a), (λ [a] b)] (Maybe b))
(apply a f)
applies a function to the value inside a
if it is a Just
, and wraps it up again. If it is Nothing
, it is just returned.
from
(λ [(Maybe a), a] a)
(from a dflt)
is an unwrapper that will get the value from a Just
, or a default value if a Nothing
is passed.
from-ptr
(λ [(Ptr a)] (Maybe a))
(from-ptr a)
Creates a (Maybe a)
from a (Ptr a)
. If the Ptr
was
NULL
, this function will return Nothing
.
just?
(λ [(Ref (Maybe a))] Bool)
(just? a)
checks whether the given value a
is a Just
.
It is the inverse of nothing?
.
nothing?
(λ [(Ref (Maybe a))] Bool)
(nothing? a)
checks whether the given value a
is a Nothing
.
It is the inverse of just?
.
or-zero
(λ [(Maybe a)] a)
(or-zero a)
is an unwrapper that will get the value from a Just
, or build
a value using zero
if a Nothing
is passed.
ptr
(λ [(Ref (Maybe a))] (Ptr a))
(ptr a)
Creates a (Ptr a)
from a (Maybe a)
. If the Maybe
was
Nothing
, this function will return a NULL
value.
to-result
(λ [(Maybe a), b] (Result a b))
(to-result a error)
is a function that will convert a Maybe
to a Result
, where a Just
becomes a Success
and a Nothing
becomes an Error
.
You’ll also need to provide an error message error
that is given to the Error
constructor if necessary.
unsafe-from
(λ [(Maybe a)] a)
(unsafe-from a)
is an unsafe unwrapper that will get the value from a Just
. If a
is Nothing
, a runtime error will be generated.