transformTry
transformTry<
T
,U
>(x
,s
,f
):TryPromise
<U
> extendsPromise
<Try
<_P
>> ?Promise
<Try
<_P
>> :TryPromise
<U
> extendsTry
<_V
> ?Try
<_V
> :Try
<TryPromise
<U
>>
This transform takes a function for either a Success
or a Failure
value. Depending
on the state of the Try
, it will apply the correct transformation and give back the result.
Any thrown exceptions during the transformation will be caught and set as Failure
value.
Example
transformTry("foobar", s => `${s}${s}`, f => `failure`)// => "foobarfoobar"
transformTry(new Error("foobar"), s => `${s}${s}`, f => `failure`)// => "failure"
Type Parameters
• T extends unknown
The input type.
• U
The transformed type.
Parameters
x
T
The Try
to transform.
s
(e
) => TryPromise
<U
>
The success transform.
f
(e
) => TryPromise
<U
>
The failure transform.
Returns
TryPromise
<U
> extends Promise
<Try
<_P
>> ? Promise
<Try
<_P
>> : TryPromise
<U
> extends Try
<_V
> ? Try
<_V
> : Try
<TryPromise
<U
>>
The transformed Try
.