Function of

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:

import * as Maybe from 'true-myth/maybe';
const foo = Maybe.of<string>(null);

This is usually only important in two cases:

  1. If you are intentionally constructing a Nothing from a known null or undefined value which is untyped.
  2. If you are specifying that the type is more general than the value passed (since TypeScript can define types as literals).

The type of the item contained in the Maybe.

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.

  • 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:

    1. If you are intentionally constructing a Nothing from a known null or undefined value which is untyped.
    2. If you are specifying that the type is more general than the value passed (since TypeScript can define types as literals).

    Type Parameters

    • F extends (...args: any) => {}

    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>

  • 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:

    1. If you are intentionally constructing a Nothing from a known null or undefined value which is untyped.
    2. If you are specifying that the type is more general than the value passed (since TypeScript can define types as literals).

    Type Parameters

    • T extends {}

      The type of the item contained in the Maybe.

    • F extends (...args: any) => 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

  • 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:

    1. If you are intentionally constructing a Nothing from a known null or undefined value which is untyped.
    2. If you are specifying that the type is more general than the value passed (since TypeScript can define types as literals).

    Type Parameters

    • F extends (...args: any) => 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

  • 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:

    1. If you are intentionally constructing a Nothing from a known null or undefined value which is untyped.
    2. If you are specifying that the type is more general than the value passed (since TypeScript can define types as literals).

    Type Parameters

    • T

      The type of the item contained in the Maybe.

    Parameters

    • value: undefined | null | 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<T>