Interface Ok<T, E>

An Ok instance is the successful variant instance of the Result type, representing a successful outcome from an operation which may fail. For a full discussion, see the module docs.

interface Ok<T, E> {
    isErr: false;
    isOk: true;
    value: T;
    variant: "Ok";
    and<U>(mAnd: Result<U, E>): Result<U, E>;
    andThen<U>(andThenFn: (t: T) => Result<U, E>): Result<U, E>;
    ap<A, B>(this: Result<(a: A) => B, E>, r: Result<A, E>): Result<B, E>;
    cast<F>(): Result<T, F>;
    equals(comparison: Result<T, E>): boolean;
    map<U>(mapFn: (t: T) => U): Result<U, E>;
    mapErr<F>(mapErrFn: (e: E) => F): Result<T, F>;
    mapOr<U>(orU: U, mapFn: (t: T) => U): U;
    mapOrElse<U>(orElseFn: (err: E) => U, mapFn: (t: T) => U): U;
    match<U>(matcher: Matcher<T, E, U>): U;
    or<F>(orResult: Result<T, F>): Result<T, F>;
    orElse<F>(orElseFn: (err: E) => Result<T, F>): Result<T, F>;
    toJSON(): ResultJSON<T, E>;
    toString(): string;
    unwrapOr<U = T>(defaultValue: U): T | U;
    unwrapOrElse<U>(elseFn: (error: E) => U): T | U;
}

Type Parameters

  • T

    The type wrapped in this Ok variant of Result.

  • E

    The type which would be wrapped in an Err variant of Result.

Hierarchy

  • Omit<ResultImpl<T, E>, "error" | "cast">
    • Ok

Properties

isErr: false

Is the Result an Err?

isOk: true

Is the Result an Ok?

value: T

The wrapped value

variant: "Ok"

Ok is always Variant.Ok.

Methods

  • 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: (err: E) => U
    • mapFn: (t: T) => U

    Returns U

  • Method variant for toString

    Returns string

  • Method variant for unwrapOr

    Type Parameters

    • U = T

    Parameters

    • defaultValue: U

    Returns T | U

  • Method variant for unwrapOrElse

    Type Parameters

    • U

    Parameters

    • elseFn: (error: E) => U

    Returns T | U