Function unwrapOr

  • Safely get the value out of the Ok variant of a Result.

    This is the recommended way to get a value out of a Result most of the time.

    import { ok, err, unwrapOr } from 'true-myth/result';

    const anOk = ok<number, string>(12);
    console.log(unwrapOr(0, anOk)); // 12

    const anErr = err<number, string>('nooooo');
    console.log(unwrapOr(0, anErr)); // 0

    Type Parameters

    • T

    • U

    • E

    Parameters

    • defaultValue: U

      The value to use if result is an Err.

    • result: Result<T, E>

      The Result instance to unwrap if it is an Ok.

    Returns U | T

    The content of result if it is an Ok, otherwise defaultValue.

    Typeparam

    T The value wrapped in the Ok.

    Typeparam

    E The value wrapped in the Err.

  • Type Parameters

    • T

    • U

    • E

    Parameters

    • defaultValue: U

    Returns ((result) => U | T)

      • (result): U | T
      • Parameters

        Returns U | T

Generated using TypeDoc