(that: boolean): (self: boolean) => boolean
(self: boolean, that: boolean): booleanCombines two booleans using XOR: (!self && that) || (self && !that).
When to use
Use to accept when exactly one boolean operand is true.
Example (Combining booleans with XOR)
import { Boolean } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(Boolean.xor(true, true), false)
assert.deepStrictEqual(Boolean.xor(true, false), true)
assert.deepStrictEqual(Boolean.xor(false, true), true)
assert.deepStrictEqual(Boolean.xor(false, false), false)export const const xor: {
(that: boolean): (self: boolean) => boolean
(self: boolean, that: boolean): boolean
}
Combines two booleans using XOR: (!self && that) || (self && !that).
When to use
Use to accept when exactly one boolean operand is true.
Example (Combining booleans with XOR)
import { Boolean } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(Boolean.xor(true, true), false)
assert.deepStrictEqual(Boolean.xor(true, false), true)
assert.deepStrictEqual(Boolean.xor(false, true), true)
assert.deepStrictEqual(Boolean.xor(false, false), false)
xor: {
(that: booleanthat: boolean): (self: booleanself: boolean) => boolean
(self: booleanself: boolean, that: booleanthat: boolean): boolean
} = dual<(...args: Array<any>) => any, (self: boolean, that: boolean) => boolean>(arity: 2, body: (self: boolean, that: boolean) => boolean): ((...args: Array<any>) => any) & ((self: boolean, that: boolean) => boolean) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(2, (self: booleanself: boolean, that: booleanthat: boolean): boolean => (!self: booleanself && that: booleanthat) || (self: booleanself && !that: booleanthat))