-
-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add chainTaskOptionKW #1744
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If chainTaskOptionK
is defined in terms of chainTaskOptionKW
then we can drop the any
assertion:
diff --git a/src/TaskEither.ts b/src/TaskEither.ts
index 3adaf404..82b3d56b 100644
--- a/src/TaskEither.ts
+++ b/src/TaskEither.ts
@@ -431,21 +431,22 @@ export const fromTaskOptionK = <E>(
/**
* @category combinators
- * @since 2.11.0
*/
-export const chainTaskOptionK = <E>(
- onNone: Lazy<E>
-): (<A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskEither<E, A>) => TaskEither<E, B>) =>
- flow(fromTaskOptionK(onNone), chain)
+export const chainTaskOptionKW = <E2>(
+ onNone: Lazy<E2>
+) => <A, B>(
+ f: (a: A) => TaskOption<B>
+) => <E1>(ma: TaskEither<E1, A>): TaskEither<E1 | E2, B> =>
+ pipe(ma, chain(fromTaskOptionK<E1 | E2>(onNone)(f)))
/**
* @category combinators
+ * @since 2.11.0
*/
-export const chainTaskOptionKW: <E2>(
- onNone: Lazy<E2>
-) => <A, B>(
- f: (a: A) => TaskOption<B>
-) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, B> = chainTaskOptionK as any
+export const chainTaskOptionK: <E>(
+ onNone: Lazy<E>
+) => (<A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskEither<E, A>) => TaskEither<E, B>) =
+ chainTaskOptionKW
/**
* @category combinators
@samhh hmm, that's a good point, if you see it fit and everything is ok go ahead and merge that, cause I'm not really familiar with the codebase too but I'm wondering, in general, is the fact the we don't assert the only benefit that we get? |
That's when the // derived
export const chainEitherK: <E, A, B>(f: (a: A) => E.Either<E, B>) => (ma: TaskEither<E, A>) => TaskEither<E, B> =
chainEitherK_(FromEither, Chain)
// asserted version
export const chainEitherKW: <E2, A, B>(
f: (a: A) => Either<E2, B>
) => <E1>(ma: TaskEither<E1, A>) => TaskEither<E1 | E2, B> = chainEitherK as any |
if we wanted to chain a function which returns TaskOption in a TaskEither pipeline we would have to do
but I thought it would be a better idea if we could do this instead: