ts-data-forge
    Preparing search index...
    • Unwraps a Result, returning the success value or a default value if it is Result.Err.

      Type Parameters

      • R extends Result.Base

        The Result.Base type to unwrap.

      • D

        The type of the default value.

      Parameters

      • result: R

        The Result to unwrap.

      • defaultValue: D

        The value to return if result is Result.Err.

      Returns D | UnwrapOk<R>

      The success value if Result.Ok, otherwise defaultValue.

      const okValue = Result.ok(10);
      const errValue = Result.err('fail');

      assert(Result.unwrapOkOr(okValue, 0) === 10);
      assert(Result.unwrapOkOr(errValue, 0) === 0);

      const unwrapWithDefault = Result.unwrapOkOr(5);

      assert(unwrapWithDefault(Result.ok(3)) === 3);
      assert(unwrapWithDefault(Result.err('no data')) === 5);
    • Unwraps a Result, returning the success value or a default value if it is Result.Err.

      Type Parameters

      • S
      • D

        The type of the default value.

      Parameters

      • defaultValue: D

        The value to return if result is Result.Err.

      Returns <E>(result: Result<S, E>) => S | D

      The success value if Result.Ok, otherwise defaultValue.

      const okValue = Result.ok(10);
      const errValue = Result.err('fail');

      assert(Result.unwrapOkOr(okValue, 0) === 10);
      assert(Result.unwrapOkOr(errValue, 0) === 0);

      const unwrapWithDefault = Result.unwrapOkOr(5);

      assert(unwrapWithDefault(Result.ok(3)) === 3);
      assert(unwrapWithDefault(Result.err('no data')) === 5);