Skip to content
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

Merged
merged 8 commits into from
Jun 6, 2024

Conversation

LaureRC
Copy link
Contributor

@LaureRC LaureRC commented Jun 4, 2024

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

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 made Either.liftPredicate dual

Related

N/A

@LaureRC LaureRC requested a review from mikearnaldi as a code owner June 4, 2024 17:53
Copy link

changeset-bot bot commented Jun 4, 2024

🦋 Changeset detected

Latest commit: f866029

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
effect Minor
@effect/cli Major
@effect/experimental Major
@effect/opentelemetry Major
@effect/platform-browser Major
@effect/platform-bun Major
@effect/platform-node-shared Major
@effect/platform-node Major
@effect/platform Major
@effect/printer-ansi Major
@effect/printer Major
@effect/rpc-http Major
@effect/rpc Major
@effect/schema Major
@effect/sql-mssql Major
@effect/sql-mysql2 Major
@effect/sql-pg Major
@effect/sql-sqlite-bun Major
@effect/sql-sqlite-node Major
@effect/sql-sqlite-react-native Major
@effect/sql-sqlite-wasm Major
@effect/sql Major
@effect/typeclass Major
@effect/vitest Major

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

@gcanti gcanti changed the base branch from main to next-minor June 6, 2024 06:28
Copy link
Contributor

@gcanti gcanti left a 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))
)

packages/effect/src/Either.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot force-pushed the next-minor branch 2 times, most recently from 96d5bf6 to 071a46c Compare June 6, 2024 10:11
@LaureRC
Copy link
Contributor Author

LaureRC commented Jun 6, 2024

Thanks for the review @gcanti! I've pushed some more commits to update what you suggested. I just had a typing issue in my tests (on this line), but fixed it by adding a NoInfer where it was needed!

@LaureRC LaureRC requested a review from gcanti June 6, 2024 11:44
@LaureRC LaureRC requested a review from gcanti June 6, 2024 12:59
@gcanti gcanti merged commit 0caa689 into Effect-TS:next-minor Jun 6, 2024
12 checks passed
@github-actions github-actions bot mentioned this pull request Jun 6, 2024
github-actions bot pushed a commit that referenced this pull request Jun 6, 2024
github-actions bot pushed a commit that referenced this pull request Jun 6, 2024
github-actions bot pushed a commit that referenced this pull request Jun 6, 2024
github-actions bot pushed a commit that referenced this pull request Jun 6, 2024
github-actions bot pushed a commit that referenced this pull request Jun 7, 2024
github-actions bot pushed a commit that referenced this pull request Jun 7, 2024
github-actions bot pushed a commit that referenced this pull request Jun 7, 2024
github-actions bot pushed a commit that referenced this pull request Jun 8, 2024
@LaureRC LaureRC mentioned this pull request Jun 8, 2024
5 tasks
github-actions bot pushed a commit that referenced this pull request Jun 14, 2024
github-actions bot pushed a commit that referenced this pull request Jun 15, 2024
github-actions bot pushed a commit that referenced this pull request Jun 16, 2024
github-actions bot pushed a commit that referenced this pull request Jun 16, 2024
github-actions bot pushed a commit that referenced this pull request Jun 16, 2024
github-actions bot pushed a commit that referenced this pull request Jun 17, 2024
github-actions bot pushed a commit that referenced this pull request Jun 17, 2024
github-actions bot pushed a commit that referenced this pull request Jun 17, 2024
github-actions bot pushed a commit that referenced this pull request Jun 17, 2024
github-actions bot pushed a commit that referenced this pull request Jun 17, 2024
github-actions bot pushed a commit that referenced this pull request Jun 17, 2024
github-actions bot pushed a commit that referenced this pull request Jun 18, 2024
github-actions bot pushed a commit that referenced this pull request Jun 18, 2024
github-actions bot pushed a commit that referenced this pull request Jun 18, 2024
github-actions bot pushed a commit that referenced this pull request Jun 18, 2024
github-actions bot pushed a commit that referenced this pull request Jun 19, 2024
github-actions bot pushed a commit that referenced this pull request Jun 19, 2024
github-actions bot pushed a commit that referenced this pull request Jun 19, 2024
github-actions bot pushed a commit that referenced this pull request Jun 20, 2024
github-actions bot pushed a commit that referenced this pull request Jun 20, 2024
github-actions bot pushed a commit that referenced this pull request Jun 20, 2024
github-actions bot pushed a commit that referenced this pull request Jun 20, 2024
github-actions bot pushed a commit that referenced this pull request Jun 20, 2024
github-actions bot pushed a commit that referenced this pull request Jun 20, 2024
github-actions bot pushed a commit that referenced this pull request Jun 20, 2024
github-actions bot pushed a commit that referenced this pull request Jun 20, 2024
github-actions bot pushed a commit that referenced this pull request Jun 20, 2024
github-actions bot pushed a commit that referenced this pull request Jun 20, 2024
github-actions bot pushed a commit that referenced this pull request Jun 20, 2024
tim-smart pushed a commit that referenced this pull request Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants