maybe.h
Exposes functions to handle the maybe data-type, which can represent either a value or nothing.
- Author: Edward Jones
- Date: 2021-09-17
dest_maybe
Destroy a maybe-type object. Any stored data must be destroyed separately.
- Param
m: Pointer to a meybe object to destroy - Param
ed: Element destructor to be called on the just field if the constructor permits
void dest_maybe(Maybe* m, Destructor ed);
fmap_maybe
Apply a function to the stored data in the maybe and output a new maybe object with the new value.
- Param
mo: Ouptut maybe object. Should be an uninitialised maybe-type pointer. - Param
mi: Input maybe object which will havefapplied to it - Param
f: Function to apply to any data insidemi
void fmap_maybe(Maybe* restrict mo, Maybe* restrict mi, Fmap f);
make_maybe_just
Construct a maybe-type object with the just constructor.
- Param
m: Pointer to a location to initialise - Param
data: Data to store in the just
void make_maybe_just(Maybe* m, void* data);
make_maybe_nothing
Construct a maybe-type object with the nothing constructor.
- Param
m: Pointer to a location to initialise
void make_maybe_nothing(Maybe* m);
succ_maybe
Check whether a maybe-type object represents a success.
- Param
m: Pointer to a maybe object
Returns: Returns true if the constructor of m is Just, otherwise false
bool succ_maybe(Maybe* m) __attribute__((pure));