Interface Just<T>

A Just instance is the present 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 Just<T> {
    isJust: true;
    isNothing: false;
    value: T;
    variant: "Just";
    and<U>(mAnd: Maybe<U>): Maybe<U>;
    andThen<U>(andThenFn: (t: T) => Maybe<U>): Maybe<U>;
    ap<A, B extends {}>(this: Maybe<(val: A) => B>, val: Maybe<A>): Maybe<B>;
    equals(comparison: Maybe<T>): boolean;
    get<K extends string | number | symbol>(key: K): Maybe<NonNullable<T[K]>>;
    map<U extends {}>(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 wrapped in this Just variant of Maybe.

Hierarchy

  • MaybeImpl<T>
    • Just

Properties

isJust: true

Is the Maybe a Just?

isNothing: false

Is the Maybe a Nothing?

value: T

The wrapped value.

variant: "Just"

Just is always Variant.Just.

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

    Returns Maybe<U>

  • Method variant for mapOr

    Type Parameters

    • U

    Parameters

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

    Returns U

  • Method variant for mapOrElse

    Type Parameters

    • U

    Parameters

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

    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

    Returns T | U