feat: add chainTaskOptionKW#1744
Merged
Merged
Conversation
samhh
reviewed
Aug 20, 2022
samhh
left a comment
Contributor
There was a problem hiding this comment.
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
Contributor
Author
|
@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? |
Owner
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 |
gcanti
requested changes
Aug 22, 2022
gcanti
approved these changes
Aug 22, 2022
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: