Hyperlinkv0.8.0-beta.28

Predicate

Predicate.xorconsteffect/Predicate.ts:1656
<A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>
<A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>

Creates a predicate that returns true if exactly one predicate is true.

When to use

Use when you want to combine two Predicates with exclusive-or semantics.

Details

Returns true when results differ.

Example (Checking exclusive-or conditions)

import { Predicate } from "effect"

const isEven = (n: number) => n % 2 === 0
const isPositive = (n: number) => n > 0
const either = Predicate.xor(isEven, isPositive)

console.log(either(-2))
combinatorsorand
export const xor: {
  <A>(that: Predicate<A>): (self: Predicate<A>) => Predicate<A>
  <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A>
} = dual(2, <A>(self: Predicate<A>, that: Predicate<A>): Predicate<A> => (a) => self(a) !== that(a))