-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dsch] introducing Result.apply method
- Loading branch information
Showing
6 changed files
with
375 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { isResult } from './guards'; | ||
import { Err, ErrTypeOf, ResolveOks } from './types'; | ||
|
||
export const resolveOks = <PR extends any[]>( | ||
args: PR, | ||
): ResolveOks<PR> | Err<ErrTypeOf<PR[number]>> => { | ||
const argValues = [] as any[]; | ||
|
||
for (const arg of args) { | ||
if (!isResult(arg)) { | ||
argValues.push(arg); | ||
} else if (arg.isErr) { | ||
return arg as Err<ErrTypeOf<PR[number]>>; | ||
} else { | ||
argValues.push(arg.value); | ||
} | ||
} | ||
|
||
return argValues as ResolveOks<PR>; | ||
}; |
Oops, something went wrong.