Create an instance of Maybe.Just
.
null
and undefined
are allowed by the type signature so that the
function may throw
on those rather than constructing a type like
Maybe<undefined>
.
Optional
value: null | TThe value to wrap in a Maybe.Just
.
Optional
An instance of Maybe.Just<T>
.
T The type of the item contained in the Maybe
.
If you pass null
or undefined
.
Create an instance of Maybe.Nothing
.
If you want to create an instance with a specific type, e.g. for use in a
function which expects a Maybe<T>
where the <T>
is known but you have no
value to give it, you can use a type parameter:
const notString = Maybe.nothing<string>();
Optional
_: nullOptional
An instance of Maybe.Nothing<T>
.
T The type of the item contained in the Maybe
.
Create a Maybe
from any value.
To specify that the result should be interpreted as a specific type, you may
invoke Maybe.of
with an explicit type parameter:
const foo = Maybe.of<string>(null);
This is usually only important in two cases:
Nothing
from a known null
or
undefined value which is untyped.The value to wrap in a Maybe
. If it is undefined
or null
,
the result will be Nothing
; otherwise it will be the type of
the value passed.
T The type of the item contained in the Maybe
.
Generated using TypeDoc
The public interface for the
Maybe
class as a value: a constructor and the associated static properties.