File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -187,3 +187,20 @@ export function unwrapErrOrFn<const TDefault>(
187
187
) : < const TReason > ( result : Result < unknown , TReason > ) => TReason | TDefault {
188
188
return result => unwrapErrOr ( result , defaultReason ) ;
189
189
}
190
+
191
+ export function unwrapErrOrElse < const TValue , const TInReason , const TOutReason > (
192
+ result : Result < TValue , TInReason > ,
193
+ elseFn : ( value : TValue ) => TOutReason
194
+ ) : TInReason | TOutReason {
195
+ if ( result instanceof Ok ) {
196
+ return elseFn ( result . value ) ;
197
+ } else {
198
+ return result . reason ;
199
+ }
200
+ }
201
+
202
+ export function unwrapErrOrElseFn < const TValue , const TOutReason > (
203
+ elseFn : ( value : TValue ) => TOutReason
204
+ ) : < const TInReason > ( result : Result < TValue , TInReason > ) => TInReason | TOutReason {
205
+ return result => unwrapErrOrElse ( result , elseFn ) ;
206
+ }
You can’t perform that action at this time.
0 commit comments