-
Notifications
You must be signed in to change notification settings - Fork 0
Function.safeTry
resultar / safeTry
safeTry<
T
,E
>(body
):Result
<T
,E
>
Evaluates the given generator to a Result returned or an Err yielded from it, whichever comes first.
This function, in combination with Result.safeUnwrap()
, is intended to emulate
Rust's ? operator.
See /tests/safeTry.test.ts
for examples.
• T
• E
• body
What is evaluated. In body, yield* result.safeUnwrap()
works as
Rust's result?
expression.
Result
<T
, E
>
The first occurence of either an yielded Err or a returned Result.
safeTry<
YieldErr
,GeneratorReturnResult
>(body
):Result
<InferOkTypes
<GeneratorReturnResult
>,InferErrTypes
<YieldErr
> |InferErrTypes
<GeneratorReturnResult
>>
• YieldErr extends Result
<never
, unknown
>
• GeneratorReturnResult extends Result
<unknown
, unknown
>
• body
Result
<InferOkTypes
<GeneratorReturnResult
>, InferErrTypes
<YieldErr
> | InferErrTypes
<GeneratorReturnResult
>>
safeTry<
T
,E
>(body
):ResultAsync
<T
,E
>
Evaluates the given generator to a Result returned or an Err yielded from it, whichever comes first.
This function, in combination with Result.safeUnwrap()
, is intended to emulate
Rust's ? operator.
See /tests/safeTry.test.ts
for examples.
• T
• E
• body
What is evaluated. In body, yield* result.safeUnwrap()
and
yield* resultAsync.safeUnwrap()
work as Rust's result?
expression.
ResultAsync
<T
, E
>
The first occurence of either an yielded Err or a returned Result.
safeTry<
YieldErr
,GeneratorReturnResult
>(body
):ResultAsync
<InferOkTypes
<GeneratorReturnResult
>,InferErrTypes
<YieldErr
> |InferErrTypes
<GeneratorReturnResult
>>
• YieldErr extends Result
<never
, unknown
>
• GeneratorReturnResult extends Result
<unknown
, unknown
>
• body
ResultAsync
<InferOkTypes
<GeneratorReturnResult
>, InferErrTypes
<YieldErr
> | InferErrTypes
<GeneratorReturnResult
>>