<A, B = A>(options: {
readonly onFalse: LazyArg<A>
readonly onTrue: LazyArg<B>
}): (value: boolean) => A | B
<A, B>(
value: boolean,
options: { readonly onFalse: LazyArg<A>; readonly onTrue: LazyArg<B> }
): A | BChooses between two lazy branches based on a boolean value.
When to use
Use to choose between two lazy branches based on a boolean value.
Example (Pattern matching on booleans)
import { Boolean } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
Boolean.match(true, {
onFalse: () => "It's false!",
onTrue: () => "It's true!"
}),
"It's true!"
)export const const match: {
<A, B = A>(options: {
readonly onFalse: LazyArg<A>
readonly onTrue: LazyArg<B>
}): (value: boolean) => A | B
<A, B>(
value: boolean,
options: {
readonly onFalse: LazyArg<A>
readonly onTrue: LazyArg<B>
}
): A | B
}
Chooses between two lazy branches based on a boolean value.
When to use
Use to choose between two lazy branches based on a boolean value.
Example (Pattern matching on booleans)
import { Boolean } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
Boolean.match(true, {
onFalse: () => "It's false!",
onTrue: () => "It's true!"
}),
"It's true!"
)
match: {
<function (type parameter) A in <A, B = A>(options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): (value: boolean) => A | B
A, function (type parameter) B in <A, B = A>(options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): (value: boolean) => A | B
B = function (type parameter) A in <A, B = A>(options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): (value: boolean) => A | B
A>(options: {
readonly onFalse: LazyArg<A>
readonly onTrue: LazyArg<B>
}
options: {
readonly onFalse: LazyArg<A>onFalse: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<function (type parameter) A in <A, B = A>(options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): (value: boolean) => A | B
A>
readonly onTrue: LazyArg<B>onTrue: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<function (type parameter) B in <A, B = A>(options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): (value: boolean) => A | B
B>
}): (value: booleanvalue: boolean) => function (type parameter) A in <A, B = A>(options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): (value: boolean) => A | B
A | function (type parameter) B in <A, B = A>(options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): (value: boolean) => A | B
B
<function (type parameter) A in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
A, function (type parameter) B in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
B>(value: booleanvalue: boolean, options: {
readonly onFalse: LazyArg<A>
readonly onTrue: LazyArg<B>
}
options: {
readonly onFalse: LazyArg<A>onFalse: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<function (type parameter) A in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
A>
readonly onTrue: LazyArg<B>onTrue: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<function (type parameter) B in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
B>
}): function (type parameter) A in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
A | function (type parameter) B in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
B
} = dual<(...args: Array<any>) => any, <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}) => A | B>(arity: 2, body: <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}) => A | B): ((...args: Array<any>) => any) & (<A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}) => A | B) (+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, <function (type parameter) A in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
A, function (type parameter) B in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
B>(value: booleanvalue: boolean, options: {
readonly onFalse: LazyArg<A>
readonly onTrue: LazyArg<B>
}
options: {
readonly onFalse: LazyArg<A>onFalse: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<function (type parameter) A in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
A>
readonly onTrue: LazyArg<B>onTrue: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<function (type parameter) B in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
B>
}): function (type parameter) A in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
A | function (type parameter) B in <A, B>(value: boolean, options: {
readonly onFalse: LazyArg<A>;
readonly onTrue: LazyArg<B>;
}): A | B
B => value: booleanvalue ? options: {
readonly onFalse: LazyArg<A>
readonly onTrue: LazyArg<B>
}
options.onTrue: LazyArg<B>onTrue() : options: {
readonly onFalse: LazyArg<A>
readonly onTrue: LazyArg<B>
}
options.onFalse: LazyArg<A>onFalse())