From 98f5c21aa65bbbca01a186a754249335b4afef57 Mon Sep 17 00:00:00 2001 From: Elizabeth Date: Mon, 2 Jun 2025 16:52:52 -0700 Subject: fixup the Either monad a bit for type safetyp --- u/process/argv.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'u/process/argv.ts') 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 = ( .map((arg) => [arg, getArg(arg, argv)] as [K, IEither]) .map(([arg, specified]): [K, IEither] => [ arg, - specified.fold((e, val) => { - const hasDefaultVal = e && defaultArgs && arg in defaultArgs; + specified.fold(({ isLeft, isRight, value}): IEither => { + if (isRight) { + return Either.right(value); + } + const hasDefaultVal = isLeft && defaultArgs && arg in defaultArgs; if (hasDefaultVal) { - return Either.right(defaultArgs[arg]!); - } else if (!val || e) { - return Either.left(e ?? new Error("unknown")); + return Either.right(defaultArgs[arg]!); } - return Either.right(val); + return Either.left(value); }), ]) .reduce( -- cgit v1.2.3-70-g09d2