Interface MaybeConstructor

The public interface for the Maybe class as a value: a constructor and the associated static properties.

interface MaybeConstructor {
    new MaybeConstructor<T>(value?: null | T): Maybe<T>;
    just: {
        <F extends (...args: any) => {}>(value: F): Maybe<F>;
        <T extends {}, F extends (...args: any) => undefined | null | T>(
            value: F,
        ): never;
        <F extends (...args: any) => undefined | null>(value: F): never;
        <T extends {}>(value: T): Maybe<T>;
    };
    nothing: <T>(_?: null) => Nothing<T>;
    of: {
        <F extends (...args: any) => {}>(value: F): Maybe<F>;
        <T extends {}, F extends (...args: any) => undefined | null | T>(
            value: F,
        ): never;
        <F extends (...args: any) => undefined | null>(value: F): never;
        <T>(value: undefined | null | T): Maybe<T>;
    };
}

Constructors

Properties

Constructors

  • Type Parameters

    • T

    Parameters

    • Optionalvalue: null | T

    Returns Maybe<T>

Properties

just: {
    <F extends (...args: any) => {}>(value: F): Maybe<F>;
    <T extends {}, F extends (...args: any) => undefined | null | T>(
        value: F,
    ): never;
    <F extends (...args: any) => undefined | null>(value: F): never;
    <T extends {}>(value: T): Maybe<T>;
}

Type declaration

    • <F extends (...args: any) => {}>(value: F): Maybe<F>
    • Create an instance of Maybe.Just.

      Type Parameters

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

      Parameters

      • value: F

        The value to wrap in a Maybe.Just.

      Returns Maybe<F>

      An instance of Maybe.Just<T>.

      If you pass null or undefined.

    • <T extends {}, F extends (...args: any) => undefined | null | T>(
          value: F,
      ): never
    • Create an instance of Maybe.Just.

      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.Just.

      Returns never

      An instance of Maybe.Just<T>.

      If you pass null or undefined.

    • <F extends (...args: any) => undefined | null>(value: F): never
    • Create an instance of Maybe.Just.

      Type Parameters

      • F extends (...args: any) => undefined | null

      Parameters

      • value: F

        The value to wrap in a Maybe.Just.

      Returns never

      An instance of Maybe.Just<T>.

      If you pass null or undefined.

    • <T extends {}>(value: T): Maybe<T>
    • Create an instance of Maybe.Just.

      Type Parameters

      • T extends {}

        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>.

      If you pass null or undefined.

nothing: <T>(_?: null) => Nothing<T>

Type declaration

    • <T>(_?: null): 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

        The type of the item contained in the Maybe.

      Parameters

      • Optional_: null

      Returns Nothing<T>

      An instance of Maybe.Nothing<T>.

of: {
    <F extends (...args: any) => {}>(value: F): Maybe<F>;
    <T extends {}, F extends (...args: any) => undefined | null | T>(
        value: F,
    ): never;
    <F extends (...args: any) => undefined | null>(value: F): never;
    <T>(value: undefined | null | T): Maybe<T>;
}

Type declaration

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

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

    • <T extends {}, F extends (...args: any) => undefined | null | T>(
          value: F,
      ): 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 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

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

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

      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>