@praha/byethrow
    Preparing search index...

    Function unwrap

    • Extracts the success value from a Result, ResultAsync.

      If the result is a Failure, it throws the contained error. For ResultAsync, it returns a Promise that resolves to the success value or rejects with the error.

      Type Parameters

      Parameters

      Returns true extends HasPromise<R> ? Promise<InferSuccess<R>> : InferSuccess<R>

      The success value, or a Promise of the success value for async results.

      The error value if the result is a Failure.

      import { Result } from '@praha/byethrow';

      const result: Result.Result<number, string> = Result.succeed(100);
      const value = Result.unwrap(result); // 100
      import { Result } from '@praha/byethrow';

      const result: Result.Result<number, string> = Result.fail('Oops');
      const value = Result.unwrap(result); // throws 'Oops'
      import { Result } from '@praha/byethrow';

      const result: Result.ResultAsync<number, string> = Result.succeed(Promise.resolve(100));
      const value = await Result.unwrap(result); // 100
      import { Result } from '@praha/byethrow';

      const result: Result.ResultAsync<number, string> = Result.fail(Promise.resolve('Oops'));
      const value = await Result.unwrap(result); // throws 'Oops'