<I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [
Pr
] extends [never]
? (input: I) => Unify<A>
: Unify<A>Returns a matcher that throws an error if no pattern matches.
When to use
Use to finalize a matcher when every remaining unmatched case should be impossible.
Details
This function finalizes a matcher by ensuring that if no patterns match, an error is thrown. It is useful when all cases should be covered, and any unexpected input should trigger an error instead of returning a default value.
When used, this function removes the need for an explicit fallback case and ensures that an unmatched value is never silently ignored.
Example (Throwing on unmatched input)
import { Match } from "effect"
const strictMatcher = Match.type<"a" | "b">().pipe(
Match.when("a", () => "Found A"),
Match.when("b", () => "Found B"),
// Will throw if input is neither "a" nor "b"
Match.orElseAbsurd
)
console.log(strictMatcher("a")) // "Found A"
console.log(strictMatcher("b")) // "Found B"
// This would throw an error at runtime:
// strictMatcher("c" as any) // throwsexport const const orElseAbsurd: <
I,
R,
RA,
A,
Pr,
Ret
>(
self: Matcher<I, R, RA, A, Pr, Ret>
) => [Pr] extends [never]
? (input: I) => Unify<A>
: Unify<A>
Returns a matcher that throws an error if no pattern matches.
When to use
Use to finalize a matcher when every remaining unmatched case should be
impossible.
Details
This function finalizes a matcher by ensuring that if no patterns match, an
error is thrown. It is useful when all cases should be covered, and any
unexpected input should trigger an error instead of returning a default
value.
When used, this function removes the need for an explicit fallback case and
ensures that an unmatched value is never silently ignored.
Example (Throwing on unmatched input)
import { Match } from "effect"
const strictMatcher = Match.type<"a" | "b">().pipe(
Match.when("a", () => "Found A"),
Match.when("b", () => "Found B"),
// Will throw if input is neither "a" nor "b"
Match.orElseAbsurd
)
console.log(strictMatcher("a")) // "Found A"
console.log(strictMatcher("b")) // "Found B"
// This would throw an error at runtime:
// strictMatcher("c" as any) // throws
orElseAbsurd: <function (type parameter) I in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>I, function (type parameter) R in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>R, function (type parameter) RA in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>RA, function (type parameter) A in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>A, function (type parameter) Pr in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>Pr, function (type parameter) Ret in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>Ret>(
self: Matcher<I, R, RA, A, Pr, Ret>self: type Matcher<
Input,
Filters,
RemainingApplied,
Result,
Provided,
Return = any
> =
| TypeMatcher<
Input,
Filters,
RemainingApplied,
Result,
Return
>
| ValueMatcher<
Input,
Filters,
RemainingApplied,
Result,
Provided,
Return
>
Union type for matchers created by Match.type and Match.value.
Details
A Matcher carries the input type, accumulated filters, remaining cases,
result type, and, for value matchers, the provided value being matched.
Example (Matching string and number values)
import { Match } from "effect"
// Simulated dynamic input that can be a string or a number
const input: string | number = "some input"
// ┌─── string
// ▼
const result = Match.value(input).pipe(
// Match if the value is a number
Match.when(Match.number, (n) => `number: ${n}`),
// Match if the value is a string
Match.when(Match.string, (s) => `string: ${s}`),
// Ensure all possible cases are covered
Match.exhaustive
)
console.log(result)
// Output: "string: some input"
Matcher<function (type parameter) I in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>I, function (type parameter) R in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>R, function (type parameter) RA in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>RA, function (type parameter) A in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>A, function (type parameter) Pr in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>Pr, function (type parameter) Ret in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>Ret>
) => [function (type parameter) Pr in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>Pr] extends [never] ? (input: Iinput: function (type parameter) I in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>I) => type Unify<A> = Values<ExtractTypes<FilterIn<A> & {
[typeSymbol]: A;
}>> extends infer Z ? Z | FilterInUnmatched<A, Keys<ExtractTypes<FilterIn<A> & {
[typeSymbol]: A;
}>>> | FilterOut<A> : never
Unifies types that implement the unification protocol.
When to use
Use to normalize unions of types that expose Effect's unification protocol.
Details
This type performs automatic type unification for types that contain
the unification symbols (unifySymbol, typeSymbol, ignoreSymbol).
It's primarily used internally by the Effect type system to handle
complex type unions and provide better type inference.
Example (Unifying protocol types)
import type { Unify } from "effect"
// Example of types that can be unified
type UnifiableA = {
value: string
[Unify.typeSymbol]?: string
[Unify.unifySymbol]?: { String: () => string }
}
type UnifiableB = {
value: number
[Unify.typeSymbol]?: number
[Unify.unifySymbol]?: { Number: () => number }
}
// Unify automatically handles the union
type Unified = Unify.Unify<UnifiableA | UnifiableB>
// Results in a properly unified type
Unify<function (type parameter) A in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>A> : type Unify<A> = Values<ExtractTypes<FilterIn<A> & {
[typeSymbol]: A;
}>> extends infer Z ? Z | FilterInUnmatched<A, Keys<ExtractTypes<FilterIn<A> & {
[typeSymbol]: A;
}>>> | FilterOut<A> : never
Unifies types that implement the unification protocol.
When to use
Use to normalize unions of types that expose Effect's unification protocol.
Details
This type performs automatic type unification for types that contain
the unification symbols (unifySymbol, typeSymbol, ignoreSymbol).
It's primarily used internally by the Effect type system to handle
complex type unions and provide better type inference.
Example (Unifying protocol types)
import type { Unify } from "effect"
// Example of types that can be unified
type UnifiableA = {
value: string
[Unify.typeSymbol]?: string
[Unify.unifySymbol]?: { String: () => string }
}
type UnifiableB = {
value: number
[Unify.typeSymbol]?: number
[Unify.unifySymbol]?: { Number: () => number }
}
// Unify automatically handles the union
type Unified = Unify.Unify<UnifiableA | UnifiableB>
// Results in a properly unified type
Unify<function (type parameter) A in <I, R, RA, A, Pr, Ret>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A>A> = import internalinternal.const orElseAbsurd: <
I,
R,
RA,
A,
Pr,
Ret
>(
self: Matcher<I, R, RA, A, Pr, Ret>
) => [Pr] extends [never]
? (input: I) => Unify<A>
: Unify<A>
orElseAbsurd