-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
Add Either.liftPredicate
#2919
Add Either.liftPredicate
#2919
Conversation
🦋 Changeset detectedLatest commit: f866029 The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
the B
type parameter seems redundant, I would remove it:
export const liftPredicate: {
<A, B extends A, E>(refinement: Refinement<NoInfer<A>, B>, orLeftWith: (a: NoInfer<A>) => E): (a: A) => Either<B, E>
<A, E>(
predicate: Predicate<NoInfer<A>>,
orLeftWith: (a: NoInfer<A>) => E
): (a: A) => Either<A, E>
<A, E, B extends A>(
self: A,
refinement: Refinement<A, B>,
orLeftWith: (a: A) => E
): Either<B, E>
<A, E>(
self: A,
predicate: Predicate<A>,
orLeftWith: (a: A) => E
): Either<A, E>
} = dual(
3,
<A, E>(a: A, predicate: Predicate<A>, orLeftWith: (a: A) => E): Either<A, E> =>
predicate(a) ? right(a) : left(orLeftWith(a))
)
96d5bf6
to
071a46c
Compare
Type
Description
Add
Either.liftPredicate
. In my current project we were missing it so we created a custom helper for it, but I found out in the Discord that other people would like it to be implemented (see thread here). So I figured it could be an opportunity to contribute here!I took inspiration from
Option.fromPredicate
but I went a bit further and madeEither.liftPredicate
dualRelated
N/A