import type { Eq } from "@principia/prelude/Eq"; import type { Either } from "../Either"; import { isLeft, isRight } from "./guards"; /* * ------------------------------------------- * Eq Either * ------------------------------------------- */ /** * ```haskell * getEq :: (Eq e, Eq a) -> Eq (Either a e) * ``` * * @category Instances * @since 1.0.0 */ export const getEq = (eqE: Eq, eqA: Eq): Eq> => { const equals_ = (x: Either, y: Either) => x === y || (isLeft(x) ? isLeft(y) && eqE.equals_(x.left, y.left) : isRight(y) && eqA.equals_(x.right, y.right)); return { equals_, equals: (y) => (x) => equals_(x, y) }; };