Function: assertFailure()
Asserts that a Result or ResultAsync is a Failure and returns it.
If the result is a Success, throws an error.
Type Param
The type of the error value.
Param
The Result or ResultAsync to assert as a Failure.
Throws
If the result is a Success.
Examples
import { Result } from '@praha/byethrow';
const result: Result.Result<number, string> = Result.fail('error');
const failure = Result.assertFailure(result);
// failure: { type: 'Failure', error: 'error' }
import { Result } from '@praha/byethrow';
const result: Result.Result<number, string> = Result.succeed(42);
Result.assertFailure(result); // throws Error
import { Result } from '@praha/byethrow';
const result: Result.Result<number, string> = getResult();
const value = Result.pipe(
result,
Result.andThen(() => Result.fail('die')),
Result.assertFailure,
Result.unwrapError(), // Safe unwrap after assertion
);
See
unwrapError - Use with assertFailure
to safely unwrap error values.
Call Signature
assertFailure<R
>(result
): Promise
<Failure
<InferFailure
<R
>>>
Defined in: functions/assert-failure.ts:53
Type Parameters
R
R
extends ResultAsync
<never
, any
>
Parameters
result
R
Returns
Promise
<Failure
<InferFailure
<R
>>>
Call Signature
assertFailure<R
>(result
): Failure
<InferFailure
<R
>>
Defined in: functions/assert-failure.ts:54
Type Parameters
R
R
extends Result
<never
, any
>
Parameters
result
R
Returns
Failure
<InferFailure
<R
>>