Skip to content

Commit

Permalink
Either: fix getEquivalence parameter order from `Either.getEquivale… (
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored and mikearnaldi committed Apr 16, 2024
1 parent 10c169e commit 271b79f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-falcons-exercise.md
@@ -0,0 +1,5 @@
---
"effect": minor
---

Either: fix `getEquivalence` parameter order from `Either.getEquivalence(left, right)` to `Either.getEquivalence({ left, right })`
12 changes: 6 additions & 6 deletions packages/effect/src/Either.ts
Expand Up @@ -287,15 +287,15 @@ export const getLeft: <R, L>(self: Either<R, L>) => Option<L> = either.getLeft
* @category equivalence
* @since 2.0.0
*/
export const getEquivalence = <R, L>(
EquivalenceL: Equivalence.Equivalence<L>,
EquivalenceR: Equivalence.Equivalence<R>
): Equivalence.Equivalence<Either<R, L>> =>
export const getEquivalence = <R, L>({ left, right }: {
right: Equivalence.Equivalence<R>
left: Equivalence.Equivalence<L>
}): Equivalence.Equivalence<Either<R, L>> =>
Equivalence.make((x, y) =>
x === y ||
(isLeft(x) ?
isLeft(y) && EquivalenceL(x.left, y.left) :
isRight(y) && EquivalenceR(x.right, y.right))
isLeft(y) && left(x.left, y.left) :
isRight(y) && right(x.right, y.right))
)

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/test/Either.test.ts
Expand Up @@ -177,7 +177,7 @@ describe("Either", () => {
})

it("getEquivalence", () => {
const isEquivalent = Either.getEquivalence(S.Equivalence, N.Equivalence)
const isEquivalent = Either.getEquivalence({ right: N.Equivalence, left: S.Equivalence })
Util.deepStrictEqual(isEquivalent(Either.right(1), Either.right(1)), true)
Util.deepStrictEqual(isEquivalent(Either.right(1), Either.right(2)), false)
Util.deepStrictEqual(isEquivalent(Either.right(1), Either.left("foo")), false)
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/Schema.ts
Expand Up @@ -5339,7 +5339,7 @@ export const EitherFromSelf = <R extends Schema.Any, L extends Schema.Any>({ lef
description: `Either<${format(right)}, ${format(left)}>`,
pretty: eitherPretty,
arbitrary: eitherArbitrary,
equivalence: (right, left) => either_.getEquivalence(left, right)
equivalence: (right, left) => either_.getEquivalence({ left, right })
}
)
}
Expand Down

0 comments on commit 271b79f

Please sign in to comment.