Interface Nothing<T>

A Nothing instance is the absent variant instance of the Maybe type, representing the presence of a value which may be absent. For a full discussion, see the module docs.

interface Nothing<T> {
    isJust: false;
    isNothing: true;
    variant: "Nothing";
    and<U>(mAnd: Maybe<U>): Maybe<U>;
    andThen<U>(andThenFn: ((t: T) => Maybe<U>)): Maybe<U>;
    ap<A, B>(this: Maybe<((val: A) => B)>, val: Maybe<A>): Maybe<B>;
    equals(comparison: Maybe<T>): boolean;
    get<K>(key: K): Maybe<NonNullable<T[K]>>;
    map<U>(mapFn: ((t: T) => U)): Maybe<U>;
    mapOr<U>(orU: U, mapFn: ((t: T) => U)): U;
    mapOrElse<U>(orElseFn: (() => U), mapFn: ((t: T) => U)): U;
    match<U>(matcher: Matcher<T, U>): U;
    or(mOr: Maybe<T>): Maybe<T>;
    orElse(orElseFn: (() => Maybe<T>)): Maybe<T>;
    toJSON(): MaybeJSON<unknown>;
    toString(): string;
    unwrapOr<U>(defaultValue: U): T | U;
    unwrapOrElse<U>(elseFn: (() => U)): T | U;
}

Type Parameters

  • T

    The type which would be wrapped in a Just variant of the Maybe.

Hierarchy

  • Omit<MaybeImpl<T>, "value">
    • Nothing

Properties

isJust: false

Is the Maybe a Just?

isNothing: true

Is the Maybe a Nothing?

variant: "Nothing"

Nothing is always Variant.Nothing.

Methods

  • Method variant for equals

    Parameters

    Returns boolean

  • Method variant for get

    If you have a Maybe of an object type, you can do thatMaybe.get('a key') to look up the next layer down in the object.

    type DeepOptionalType = {
    something?: {
    with?: {
    deeperKeys?: string;
    }
    }
    };

    const fullySet: DeepType = {
    something: {
    with: {
    deeperKeys: 'like this'
    }
    }
    };

    const deepJust = Maybe.of(fullySet)
    .get('something')
    .get('with')
    .get('deeperKeys');

    console.log(deepJust); // Just('like this');

    const partiallyUnset: DeepType = { something: { } };

    const deepEmpty = Maybe.of(partiallyUnset)
    .get('something')
    .get('with')
    .get('deeperKeys');

    console.log(deepEmpty); // Nothing

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • key: K

    Returns Maybe<NonNullable<T[K]>>

  • Method variant for map

    Type Parameters

    • U extends {}

    Parameters

    • mapFn: ((t: T) => U)
        • (t): U
        • Parameters

          Returns U

    Returns Maybe<U>

  • Method variant for mapOr

    Type Parameters

    • U

    Parameters

    • orU: U
    • mapFn: ((t: T) => U)
        • (t): U
        • Parameters

          Returns U

    Returns U

  • Method variant for mapOrElse

    Type Parameters

    • U

    Parameters

    • orElseFn: (() => U)
        • (): U
        • Returns U

    • mapFn: ((t: T) => U)
        • (t): U
        • Parameters

          Returns U

    Returns U

  • Method variant for match

    Type Parameters

    • U

    Parameters

    Returns U

  • Method variant for toString

    Returns string

  • Method variant for unwrapOr

    Type Parameters

    • U

    Parameters

    • defaultValue: U

    Returns T | U

  • Method variant for unwrapOrElse

    Type Parameters

    • U

    Parameters

    • elseFn: (() => U)
        • (): U
        • Returns U

    Returns T | U