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

      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.Ok.

      Returns D | UnwrapErr<R>

      The error value if Result.Err, otherwise defaultValue.

      const okResult = Result.ok('success');
      const errResult = Result.err('failure');

      assert(Result.unwrapErrOr(okResult, 'default') === 'default');
      assert(Result.unwrapErrOr(errResult, 'default') === 'failure');

      const unwrapError = Result.unwrapErrOr('fallback error');

      assert(unwrapError(Result.err('boom')) === 'boom');
      assert(unwrapError(Result.ok('no error')) === 'fallback error');
    • Unwraps a Result, returning the error value or a default value if it is Result.Ok.

      Type Parameters

      • E
      • D

        The type of the default value.

      Parameters

      • defaultValue: D

        The value to return if result is Result.Ok.

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

      The error value if Result.Err, otherwise defaultValue.

      const okResult = Result.ok('success');
      const errResult = Result.err('failure');

      assert(Result.unwrapErrOr(okResult, 'default') === 'default');
      assert(Result.unwrapErrOr(errResult, 'default') === 'failure');

      const unwrapError = Result.unwrapErrOr('fallback error');

      assert(unwrapError(Result.err('boom')) === 'boom');
      assert(unwrapError(Result.ok('no error')) === 'fallback error');