True Myth / maybe / MaybeConstructor
Interface: MaybeConstructor
The public interface for the Maybe
class as a value: a constructor and the associated static properties.
Constructors
Constructor
new MaybeConstructor<
T
>(value?
):Maybe
<T
>
Parameters
value?
null
| T
Returns
Maybe
<T
>
Properties
just()
just: {<
F
>(value
):Maybe
<F
>; <T
,F
>(value
):never
; <F
>(value
):never
; <T
>(value
):Maybe
<T
>; }
Call Signature
<
F
>(value
):Maybe
<F
>
Create an instance of Maybe.Just
.
Type Parameters
F
F
extends (...args
) => object
Parameters
value
F
The value to wrap in a Maybe.Just
.
Returns
Maybe
<F
>
An instance of Maybe.Just<T>
.
Throws
If you pass null
or undefined
.
Call Signature
<
T
,F
>(value
):never
Create an instance of Maybe.Just
.
Type Parameters
T
T
extends object
The type of the item contained in the Maybe
.
F
F
extends (...args
) => undefined
| null
| T
Parameters
value
F
The value to wrap in a Maybe.Just
.
Returns
never
An instance of Maybe.Just<T>
.
Throws
If you pass null
or undefined
.
Call Signature
<
F
>(value
):never
Create an instance of Maybe.Just
.
Type Parameters
F
F
extends (...args
) => undefined
| null
Parameters
value
F
The value to wrap in a Maybe.Just
.
Returns
never
An instance of Maybe.Just<T>
.
Throws
If you pass null
or undefined
.
Call Signature
<
T
>(value
):Maybe
<T
>
Create an instance of Maybe.Just
.
Type Parameters
T
T
extends object
The type of the item contained in the Maybe
.
Parameters
value
T
The value to wrap in a Maybe.Just
.
Returns
Maybe
<T
>
An instance of Maybe.Just<T>
.
Throws
If you pass null
or undefined
.
nothing()
nothing: <
T
>(_?
) =>Nothing
<T
>
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>();
Type Parameters
T
T
The type of the item contained in the Maybe
.
Parameters
_?
null
Returns
Nothing
<T
>
An instance of Maybe.Nothing<T>
.
of()
of: {<
F
>(value
):Maybe
<F
>; <T
,F
>(value
):never
; <F
>(value
):never
; <T
>(value
):Maybe
<T
>; <T
>(value
):Maybe
<NonNullable
<T
>>; }
Call Signature
<
F
>(value
):Maybe
<F
>
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:
- If you are intentionally constructing a
Nothing
from a knownnull
or undefined value which is untyped. - If you are specifying that the type is more general than the value passed (since TypeScript can define types as literals).
Type Parameters
F
F
extends (...args
) => object
Parameters
value
F
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.
Returns
Maybe
<F
>
Call Signature
<
T
,F
>(value
):never
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:
- If you are intentionally constructing a
Nothing
from a knownnull
or undefined value which is untyped. - If you are specifying that the type is more general than the value passed (since TypeScript can define types as literals).
Type Parameters
T
T
extends object
The type of the item contained in the Maybe
.
F
F
extends (...args
) => undefined
| null
| T
Parameters
value
F
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.
Returns
never
Call Signature
<
F
>(value
):never
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:
- If you are intentionally constructing a
Nothing
from a knownnull
or undefined value which is untyped. - If you are specifying that the type is more general than the value passed (since TypeScript can define types as literals).
Type Parameters
F
F
extends (...args
) => undefined
| null
Parameters
value
F
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.
Returns
never
Call Signature
<
T
>(value
):Maybe
<T
>
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:
- If you are intentionally constructing a
Nothing
from a knownnull
or undefined value which is untyped. - If you are specifying that the type is more general than the value passed (since TypeScript can define types as literals).
Type Parameters
T
T
extends object
The type of the item contained in the Maybe
.
Parameters
value
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.
undefined
| null
| T
Returns
Maybe
<T
>
Call Signature
<
T
>(value
):Maybe
<NonNullable
<T
>>
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:
- If you are intentionally constructing a
Nothing
from a knownnull
or undefined value which is untyped. - If you are specifying that the type is more general than the value passed (since TypeScript can define types as literals).
Type Parameters
T
T
The type of the item contained in the Maybe
.
Parameters
value
T
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.
Returns
Maybe
<NonNullable
<T
>>