<B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>
readonly onDefined: (a: A) => C
}): (self: A | undefined) => B | C
<A, B, C = B>(
self: A | undefined,
options: {
readonly onUndefined: LazyArg<B>
readonly onDefined: (a: A) => C
}
): B | CPattern matches on an A | undefined value, running onDefined when the
value is present or evaluating onUndefined when the value is undefined.
When to use
Use when you need to turn an A | undefined into a non-optional result by
handling both the defined and undefined branches in one expression.
export const const match: {
<B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>
readonly onDefined: (a: A) => C
}): (self: A | undefined) => B | C
<A, B, C = B>(
self: A | undefined,
options: {
readonly onUndefined: LazyArg<B>
readonly onDefined: (a: A) => C
}
): B | C
}
Pattern matches on an A | undefined value, running onDefined when the
value is present or evaluating onUndefined when the value is undefined.
When to use
Use when you need to turn an A | undefined into a non-optional result by
handling both the defined and undefined branches in one expression.
match: {
<function (type parameter) B in <B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): (self: A | undefined) => B | C
B, function (type parameter) A in <B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): (self: A | undefined) => B | C
A, function (type parameter) C in <B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): (self: A | undefined) => B | C
C = function (type parameter) B in <B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): (self: A | undefined) => B | C
B>(options: {
readonly onUndefined: LazyArg<B>
readonly onDefined: (a: A) => C
}
options: {
readonly onUndefined: LazyArg<B>onUndefined: 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 <B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): (self: A | undefined) => B | C
B>
readonly onDefined: (a: A) => ConDefined: (a: Aa: function (type parameter) A in <B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): (self: A | undefined) => B | C
A) => function (type parameter) C in <B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): (self: A | undefined) => B | C
C
}): (self: A | undefinedself: function (type parameter) A in <B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): (self: A | undefined) => B | C
A | undefined) => function (type parameter) B in <B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): (self: A | undefined) => B | C
B | function (type parameter) C in <B, A, C = B>(options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): (self: A | undefined) => B | C
C
<function (type parameter) A in <A, B, C = B>(self: A | undefined, options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
A, function (type parameter) B in <A, B, C = B>(self: A | undefined, options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
B, function (type parameter) C in <A, B, C = B>(self: A | undefined, options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
C = function (type parameter) B in <A, B, C = B>(self: A | undefined, options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
B>(self: A | undefinedself: function (type parameter) A in <A, B, C = B>(self: A | undefined, options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
A | undefined, options: {
readonly onUndefined: LazyArg<B>
readonly onDefined: (a: A) => C
}
options: {
readonly onUndefined: LazyArg<B>onUndefined: 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, C = B>(self: A | undefined, options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
B>
readonly onDefined: (a: A) => ConDefined: (a: Aa: function (type parameter) A in <A, B, C = B>(self: A | undefined, options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
A) => function (type parameter) C in <A, B, C = B>(self: A | undefined, options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
C
}): function (type parameter) B in <A, B, C = B>(self: A | undefined, options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
B | function (type parameter) C in <A, B, C = B>(self: A | undefined, options: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
C
} = dual<(...args: Array<any>) => any, <A, B, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}) => B | C>(arity: 2, body: <A, B, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}) => B | C): ((...args: Array<any>) => any) & (<A, B, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}) => B | C) (+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, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
A, function (type parameter) B in <A, B, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
B, function (type parameter) C in <A, B, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
C = function (type parameter) B in <A, B, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
B>(self: A | undefinedself: function (type parameter) A in <A, B, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
A | undefined, { onDefined: (a: A) => ConDefined, onUndefined: LazyArg<B>onUndefined }: {
readonly onUndefined: LazyArg<B>onUndefined: 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, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
B>
readonly onDefined: (a: A) => ConDefined: (a: Aa: function (type parameter) A in <A, B, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
A) => function (type parameter) C in <A, B, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
C
}): function (type parameter) B in <A, B, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
B | function (type parameter) C in <A, B, C = B>(self: A | undefined, { onDefined, onUndefined }: {
readonly onUndefined: LazyArg<B>;
readonly onDefined: (a: A) => C;
}): B | C
C => self: A | undefinedself === var undefinedundefined ? onUndefined: LazyArg<B>onUndefined() : onDefined: (a: A) => ConDefined(self: A & ({} | null)self)
)