summaryrefslogtreecommitdiff
path: root/u/process
diff options
context:
space:
mode:
authorElizabeth <me@liz.coffee>2025-06-02 16:52:52 -0700
committerElizabeth <me@liz.coffee>2025-06-02 16:52:52 -0700
commit98f5c21aa65bbbca01a186a754249335b4afef57 (patch)
tree0fc8e01a73f0a3be4534c11724ad2ff634b4fd2f /u/process
parent373d9ec700c0097a22cf665a8e33cf48998d1dc2 (diff)
downloadci-98f5c21aa65bbbca01a186a754249335b4afef57.tar.gz
ci-98f5c21aa65bbbca01a186a754249335b4afef57.zip
fixup the Either monad a bit for type safetyp
Diffstat (limited to 'u/process')
-rw-r--r--u/process/argv.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/u/process/argv.ts b/u/process/argv.ts
index 657c9a7..7190531 100644
--- a/u/process/argv.ts
+++ b/u/process/argv.ts
@@ -37,14 +37,15 @@ export const argv = <K extends string, V extends string>(
.map((arg) => [arg, getArg(arg, argv)] as [K, IEither<Error, V>])
.map(([arg, specified]): [K, IEither<Error, V>] => [
arg,
- specified.fold((e, val) => {
- const hasDefaultVal = e && defaultArgs && arg in defaultArgs;
+ specified.fold(({ isLeft, isRight, value}): IEither<Error, V> => {
+ if (isRight) {
+ return Either.right(value);
+ }
+ const hasDefaultVal = isLeft && defaultArgs && arg in defaultArgs;
if (hasDefaultVal) {
- return Either.right<Error, V>(defaultArgs[arg]!);
- } else if (!val || e) {
- return Either.left<Error, V>(e ?? new Error("unknown"));
+ return Either.right(defaultArgs[arg]!);
}
- return Either.right<Error, V>(val);
+ return Either.left(value);
}),
])
.reduce(