Skip to content

Commit

Permalink
Remove unnecessary === comparison in getEquivalence functions (#2948
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gcanti authored Jun 7, 2024
1 parent 38bda05 commit 3a77e20
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changeset/tasty-toys-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"effect": patch
---

Remove unnecessary `===` comparison in `getEquivalence` functions

In some `getEquivalence` functions that use `make`, there is an unnecessary `===` comparison. The `make` function already handles this comparison.
5 changes: 2 additions & 3 deletions packages/effect/src/Either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,9 @@ export const getEquivalence = <R, L>({ left, right }: {
left: Equivalence.Equivalence<L>
}): Equivalence.Equivalence<Either<R, L>> =>
Equivalence.make((x, y) =>
x === y ||
(isLeft(x) ?
isLeft(x) ?
isLeft(y) && left(x.left, y.left) :
isRight(y) && right(x.right, y.right))
isRight(y) && right(x.right, y.right)
)

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/src/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ export const filter: {
* @since 2.0.0
*/
export const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equivalence.Equivalence<Option<A>> =>
Equivalence.make((x, y) => x === y || (isNone(x) ? isNone(y) : isNone(y) ? false : isEquivalent(x.value, y.value)))
Equivalence.make((x, y) => isNone(x) ? isNone(y) : isNone(y) ? false : isEquivalent(x.value, y.value))

/**
* The `Order` instance allows `Option` values to be compared with
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/src/Redacted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ export const unsafeWipe: <A>(self: Redacted<A>) => boolean = redacted_.unsafeWip
* @since 3.3.0
*/
export const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equivalence.Equivalence<Redacted<A>> =>
Equivalence.make((x, y) => x === y || (isEquivalent(value(x), value(y))))
Equivalence.make((x, y) => isEquivalent(value(x), value(y)))

0 comments on commit 3a77e20

Please sign in to comment.