diff --git a/packages/effect/src/Either.ts b/packages/effect/src/Either.ts index 65767ae951f..cf82f645599 100644 --- a/packages/effect/src/Either.ts +++ b/packages/effect/src/Either.ts @@ -315,9 +315,9 @@ export const getEquivalence = ({ left, right }: { left: Equivalence.Equivalence }): Equivalence.Equivalence> => Equivalence.make((x, y) => - isLeft(x) ? - isLeft(y) && left(x.left, y.left) : - isRight(y) && right(x.right, y.right) + isRight(x) ? + isRight(y) && right(x.right, y.right) : + isLeft(y) && left(x.left, y.left) ) /** @@ -338,7 +338,7 @@ export const mapBoth: { (self: Either, { onLeft, onRight }: { readonly onLeft: (left: E) => E2 readonly onRight: (right: A) => A2 - }): Either => isLeft(self) ? left(onLeft(self.left)) : right(onRight(self.right)) + }): Either => isRight(self) ? right(onRight(self.right)) : left(onLeft(self.left)) ) /** @@ -353,7 +353,7 @@ export const mapLeft: { } = dual( 2, (self: Either, f: (left: E) => E2): Either => - isLeft(self) ? left(f(self.left)) : right(self.right) + isRight(self) ? right(self.right) : left(f(self.left)) ) /** @@ -408,7 +408,7 @@ export const match: { (self: Either, { onLeft, onRight }: { readonly onLeft: (left: E) => B readonly onRight: (right: A) => C - }): B | C => isLeft(self) ? onLeft(self.left) : onRight(self.right) + }): B | C => isRight(self) ? onRight(self.right) : onLeft(self.left) ) /** @@ -538,7 +538,7 @@ export const getOrElse: { (self: Either, onLeft: (left: E) => A2): A | A2 } = dual( 2, - (self: Either, onLeft: (left: E) => A2): A | A2 => isLeft(self) ? onLeft(self.left) : self.right + (self: Either, onLeft: (left: E) => A2): A | A2 => isRight(self) ? self.right : onLeft(self.left) ) /** @@ -637,7 +637,7 @@ export const orElse: { } = dual( 2, (self: Either, that: (left: E) => Either): Either => - isLeft(self) ? that(self.left) : right(self.right) + isRight(self) ? right(self.right) : that(self.left) ) /** @@ -650,7 +650,7 @@ export const flatMap: { } = dual( 2, (self: Either, f: (right: A) => Either): Either => - isLeft(self) ? left(self.left) : f(self.right) + isRight(self) ? f(self.right) : left(self.left) ) /** @@ -773,7 +773,7 @@ export const all: > | Record(self: Either): Either => isLeft(self) ? right(self.left) : left(self.right) +export const flip = (self: Either): Either => isRight(self) ? left(self.right) : right(self.left) const adapter = Gen.adapter() diff --git a/packages/effect/src/Option.ts b/packages/effect/src/Option.ts index 9edcb23869f..1772ddeb479 100644 --- a/packages/effect/src/Option.ts +++ b/packages/effect/src/Option.ts @@ -310,7 +310,7 @@ export const match: { (self: Option, { onNone, onSome }: { readonly onNone: LazyArg readonly onSome: (a: A) => C - }): B | C => isNone(self) ? onNone() : onSome(self.value) + }): B | C => isSome(self) ? onSome(self.value) : onNone() ) /** @@ -502,7 +502,7 @@ export const getOrElse: { (self: Option, onNone: LazyArg): A | B } = dual( 2, - (self: Option, onNone: LazyArg): A | B => isNone(self) ? onNone() : self.value + (self: Option, onNone: LazyArg): A | B => isSome(self) ? self.value : onNone() ) /** @@ -546,7 +546,7 @@ export const orElse: { (self: Option, that: LazyArg>): Option } = dual( 2, - (self: Option, that: LazyArg>): Option => isNone(self) ? that() : self + (self: Option, that: LazyArg>): Option => isSome(self) ? self : that() ) /** @@ -583,7 +583,7 @@ export const orElseSome: { (self: Option, onNone: LazyArg): Option } = dual( 2, - (self: Option, onNone: LazyArg): Option => isNone(self) ? some(onNone()) : self + (self: Option, onNone: LazyArg): Option => isSome(self) ? self : some(onNone()) ) /** @@ -615,7 +615,7 @@ export const orElseEither: { } = dual( 2, (self: Option, that: LazyArg>): Option> => - isNone(self) ? map(that(), either.right) : map(self, either.left) + isSome(self) ? map(self, either.left) : map(that(), either.right) ) /** @@ -925,7 +925,7 @@ export const map: { (self: Option, f: (a: A) => B): Option } = dual( 2, - (self: Option, f: (a: A) => B): Option => isNone(self) ? none() : some(f(self.value)) + (self: Option, f: (a: A) => B): Option => isSome(self) ? some(f(self.value)) : none() ) /** @@ -1049,7 +1049,7 @@ export const flatMap: { (self: Option, f: (a: A) => Option): Option } = dual( 2, - (self: Option, f: (a: A) => Option): Option => isNone(self) ? none() : f(self.value) + (self: Option, f: (a: A) => Option): Option => isSome(self) ? f(self.value) : none() ) /** @@ -1148,7 +1148,7 @@ export const flatMapNullable: { } = dual( 2, (self: Option, f: (a: A) => B | null | undefined): Option> => - isNone(self) ? none() : fromNullable(f(self.value)) + isSome(self) ? fromNullable(f(self.value)) : none() ) /** @@ -1542,7 +1542,7 @@ export const reduceCompact: { * @category Conversions * @since 2.0.0 */ -export const toArray = (self: Option): Array => isNone(self) ? [] : [self.value] +export const toArray = (self: Option): Array => isSome(self) ? [self.value] : [] /** * Splits an `Option` into two `Option`s based on the result of a mapping @@ -1854,7 +1854,7 @@ export const liftPredicate: { // Note: I intentionally avoid using the NoInfer p export const containsWith = (isEquivalent: (self: A, that: A) => boolean): { (a: A): (self: Option) => boolean (self: Option, a: A): boolean -} => dual(2, (self: Option, a: A): boolean => isNone(self) ? false : isEquivalent(self.value, a)) +} => dual(2, (self: Option, a: A): boolean => isSome(self) ? isEquivalent(self.value, a) : false) const _equivalence = Equal.equivalence() @@ -1934,7 +1934,7 @@ export const exists: { } = dual( 2, (self: Option, refinement: Refinement): self is Option => - isNone(self) ? false : refinement(self.value) + isSome(self) ? refinement(self.value) : false ) // -------------------------------------------------------------------------------------