Loading...
Searching...
No Matches
maybe.h File Reference

An optional value. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Macros

#define | ML99_just(x) ML99_call(ML99_just, x)
| Some value `x`.
#define | ML99_nothing(...) ML99_callUneval(ML99_nothing, )
| No value.
#define | ML99_isJust(maybe) ML99_call(ML99_isJust, maybe)
| `ML99_true()` if `maybe` contains some value, otherwise `ML99_false()`.
#define | ML99_isNothing(maybe) ML99_call(ML99_isNothing, maybe)
| The inverse of ML99_isJust.
#define | ML99_maybeEq(cmp, maybe, other) ML99_call(ML99_maybeEq, cmp, maybe, other)
| Tests `maybe` and `other` for equality.
#define | ML99_maybeUnwrap(maybe) ML99_call(ML99_maybeUnwrap, maybe)
| Returns the contained value on `ML99_just(x)` or emits a fatal error on `ML99_nothing()`.
#define | ML99_JUST(x) ML99_CHOICE(just, x)
#define | ML99_NOTHING(...) ML99_CHOICE(nothing, ~)
#define | ML99_IS_JUST(maybe) ML99_PRIV_IS_JUST(maybe)
#define | ML99_IS_NOTHING(maybe) ML99_NOT(ML99_IS_JUST(maybe))

## Detailed Description

An optional value.

## Macro Definition Documentation

## ML99_isJust

#define ML99_isJust | ( |  | maybe | ) | ML99_call(ML99_isJust, maybe)

`ML99_true()` if `maybe` contains some value, otherwise `ML99_false()`.

# Examples

#include <metalang99/maybe.h>
// 1
ML99_isJust(ML99_just(v(123)))
// 0
ML99_isJust(ML99_nothing())
v
#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition lang.h:145
maybe.h
An optional value.
ML99_nothing
#define ML99_nothing(...)
No value.
Definition maybe.h:23
ML99_isJust
#define ML99_isJust(maybe)
ML99_true() if maybe contains some value, otherwise ML99_false().
Definition maybe.h:40
ML99_just
#define ML99_just(x)
Some value x.
Definition maybe.h:18

## ML99_isNothing

#define ML99_isNothing | ( |  | maybe | ) | ML99_call(ML99_isNothing, maybe)

The inverse of ML99_isJust.

# Examples

#include <metalang99/maybe.h>
// 1
ML99_isNothing(ML99_nothing())
// 0
ML99_isNothing(ML99_just(v(123)))
ML99_isNothing
#define ML99_isNothing(maybe)
The inverse of ML99_isJust.
Definition maybe.h:57

## ML99_maybeEq

#define ML99_maybeEq | ( |  | cmp,
|  |  | maybe,
|  |  | other
| ) |  | ML99_call(ML99_maybeEq, cmp, maybe, other)

Tests `maybe` and `other` for equality.

# Examples

#include <metalang99/maybe.h>
#include <metalang99/nat.h>
// 1
ML99_maybeEq(v(ML99_natEq), ML99_just(v(123)), ML99_just(v(123)));
// 0
ML99_maybeEq(v(ML99_natEq), ML99_just(v(4)), ML99_just(v(6)));
// 0
ML99_maybeEq(v(ML99_natEq), ML99_just(v(4)), ML99_nothing());
ML99_maybeEq
#define ML99_maybeEq(cmp, maybe, other)
Tests maybe and other for equality.
Definition maybe.h:78
nat.h
Natural numbers: [0; 255].
ML99_natEq
#define ML99_natEq(x, y)
Definition nat.h:112

## ML99_maybeUnwrap

#define ML99_maybeUnwrap | ( |  | maybe | ) | ML99_call(ML99_maybeUnwrap, maybe)

Returns the contained value on `ML99_just(x)` or emits a fatal error on `ML99_nothing()`.

# Examples

#include <metalang99/maybe.h>
// 123
ML99_maybeUnwrap(ML99_just(v(123)))
// Emits a fatal error.
ML99_maybeUnwrap(ML99_nothing())
ML99_maybeUnwrap
#define ML99_maybeUnwrap(maybe)
Returns the contained value on ML99_just(x) or emits a fatal error on ML99_nothing().
Definition maybe.h:95