interface Maybe<T> {
    alt(other: functional.Maybe<T>): functional.Maybe<T>;
    altLazy(other: () => functional.Maybe<T>): functional.Maybe<T>;
    ap<U>(maybeF: functional.Maybe<(value: T) => U>): functional.Maybe<U>;
    caseOf<U>(patterns: functional.MaybePatterns<T, U>): U;
    chain<U>(f: (value: T) => functional.Maybe<U>): functional.Maybe<U>;
    chainNullable<U>(
        f: (value: T) => undefined | null | void | U,
    ): functional.Maybe<U>;
    equals(other: functional.Maybe<T>): boolean;
    extend<U>(f: (value: functional.Maybe<T>) => U): functional.Maybe<U>;
    extract(): ExtractMaybe<T, undefined>;
    extractNullable(): ExtractMaybe<T, null>;
    "fantasy-land/alt"(other: functional.Maybe<T>): functional.Maybe<T>;
    "fantasy-land/ap"<U>(
        maybeF: functional.Maybe<(value: T) => U>,
    ): functional.Maybe<U>;
    "fantasy-land/chain"<U>(
        f: (value: T) => functional.Maybe<U>,
    ): functional.Maybe<U>;
    "fantasy-land/equals"(other: functional.Maybe<T>): boolean;
    "fantasy-land/extend"<U>(
        f: (value: functional.Maybe<T>) => U,
    ): functional.Maybe<U>;
    "fantasy-land/filter"<U>(pred: (value: T) => boolean): functional.Maybe<U>;
    "fantasy-land/filter"(pred: (value: T) => boolean): functional.Maybe<T>;
    "fantasy-land/map"<U>(f: (value: T) => U): functional.Maybe<U>;
    "fantasy-land/reduce"<U>(
        reducer: (accumulator: U, value: T) => U,
        initialValue: U,
    ): U;
    filter<U>(pred: (value: T) => value is U): functional.Maybe<U>;
    filter(pred: (value: T) => boolean): functional.Maybe<T>;
    ifJust(effect: (value: T) => any): this;
    ifNothing(effect: () => any): this;
    inspect(): string;
    isJust(): this is AlwaysJust;
    isNothing(): this is Nothing;
    join<U>(this: functional.Maybe<functional.Maybe<U>>): functional.Maybe<U>;
    map<U>(f: (value: T) => U): functional.Maybe<U>;
    mapOrDefault<U>(f: (value: T) => U, defaultValue: U): U;
    orDefault(defaultValue: T): T;
    orDefaultLazy(getDefaultValue: () => T): T;
    reduce<U>(reducer: (accumulator: U, value: T) => U, initialValue: U): U;
    toEither<L>(left: L): functional.Either<L, T>;
    toJSON(): T;
    toList(): T[];
    toString(): string;
    unsafeCoerce(): T;
}

Type Parameters

  • T

Methods

  • Transforms this with a function that returns a nullable value. Equivalent to m.chain(x => Maybe.fromNullable(f(x)))

    Type Parameters

    • U

    Parameters

    • f: (value: T) => undefined | null | void | U

    Returns functional.Maybe<U>

  • Compares the values inside this and the argument, returns true if both are Nothing or if the values are equal

    Parameters

    Returns boolean

  • Returns the value inside this or undefined if this is Nothing. Use extractNullable if you need a null returned instead

    Returns ExtractMaybe<T, undefined>

  • Returns the value inside this or null if this is Nothing. Use extract if you need an undefined returned instead

    Returns ExtractMaybe<T, null>

  • Type Parameters

    • U

    Parameters

    • pred: (value: T) => boolean

    Returns functional.Maybe<U>

  • Parameters

    • pred: (value: T) => boolean

    Returns functional.Maybe<T>

  • Type Parameters

    • U

    Parameters

    • reducer: (accumulator: U, value: T) => U
    • initialValue: U

    Returns U

  • Takes a predicate function and returns this if the predicate returns true or Nothing if it returns false

    Type Parameters

    • U

    Parameters

    • pred: (value: T) => value is U

    Returns functional.Maybe<U>

  • Takes a predicate function and returns this if the predicate returns true or Nothing if it returns false

    Parameters

    • pred: (value: T) => boolean

    Returns functional.Maybe<T>

  • Runs an effect if this is Just, returns this to make chaining other methods possible

    Parameters

    • effect: (value: T) => any

    Returns this

  • Runs an effect if this is Nothing, returns this to make chaining other methods possible

    Parameters

    • effect: () => any

    Returns this

  • Returns string

  • Returns true if this is Just, otherwise it returns false

    Returns this is AlwaysJust

  • Returns true if this is Nothing, otherwise it returns false

    Returns this is Nothing

  • Transforms the value inside this with a given function. Returns Nothing if this is Nothing

    Type Parameters

    • U

    Parameters

    • f: (value: T) => U

    Returns functional.Maybe<U>

  • Maps over this and returns the resulting value or returns the default value if this is Nothing

    Type Parameters

    • U

    Parameters

    • f: (value: T) => U
    • defaultValue: U

    Returns U

  • Returns the default value if this is Nothing, otherwise it return the value inside this

    Parameters

    • defaultValue: T

    Returns T

  • Lazy version of orDefault. Takes a function that returns the default value, that function will be called only if this is Nothing

    Parameters

    • getDefaultValue: () => T

    Returns T

  • Takes a reducer and an initial value and returns the initial value if this is Nothing or the result of applying the function to the initial value and the value inside this

    Type Parameters

    • U

    Parameters

    • reducer: (accumulator: U, value: T) => U
    • initialValue: U

    Returns U

  • Constructs a Right from a Just or a Left with a provided left value if this is Nothing

    Type Parameters

    • L

    Parameters

    • left: L

    Returns functional.Either<L, T>

  • Returns T

  • Returns empty list if the Maybe is Nothing or a list where the only element is the value of Just

    Returns T[]

  • Returns string

  • Returns the value inside this or throws an error if this is Nothing

    Returns T