From 07a74315e1d85c97ddf5c9eac26ef2036ab9b3e3 Mon Sep 17 00:00:00 2001 From: themodernhakr Date: Mon, 9 Jun 2025 00:56:38 -0500 Subject: [PATCH] Add bindL to DoEither --- src/either.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/either.ts b/src/either.ts index 3e3e03c..c6977eb 100644 --- a/src/either.ts +++ b/src/either.ts @@ -106,6 +106,26 @@ export class DoEither, E> { return new DoEither(newEither) } + /** + * Binds a new value to the scope using a lazily evaluated Either + * @typeParam K - The key to bind to + * @typeParam A - The type of the value to bind + * @param key - The property name to bind to + * @param f - Function returning the Either value to bind (receives current scope) + * @returns A new DoEither instance with the extended scope + */ + bindL( + key: K, + f: (scope: T) => Either, + ): DoEither, E> { + const newEither = eitherChain, E>((scope: T) => + eitherMap, E>((a: A) => ({...scope, [key]: a}))( + f(scope), + ) + )(this.either) + return new DoEither(newEither) + } + /** * Returns the final result from the scope * @typeParam B - The return type