<I>(): Matcher<I, Types.Without<never>, I, never, never>Creates a matcher for a specific type.
When to use
Use to build a reusable matcher function for values of a known input type.
Details
This function defines a Matcher that operates on a given type, allowing you
to specify conditions for handling different cases. Once the matcher is
created, you can use pattern-matching functions like when to define
how different values should be processed.
Example (Matching Numbers and Strings)
import { Match } from "effect"
// Create a matcher for values that are either strings or numbers
//
// ┌─── (u: string | number) => string
// ▼
const match = Match.type<string | number>().pipe(
// Match when the value is a number
Match.when(Match.number, (n) => `number: ${n}`),
// Match when the value is a string
Match.when(Match.string, (s) => `string: ${s}`),
// Ensure all possible cases are handled
Match.exhaustive
)
console.log(match(0))
// Output: "number: 0"
console.log(match("hello"))
// Output: "string: hello"export const const type: <I>() => Matcher<
I,
Types.Without<never>,
I,
never,
never
>
Creates a matcher for a specific type.
When to use
Use to build a reusable matcher function for values of a known input type.
Details
This function defines a Matcher that operates on a given type, allowing you
to specify conditions for handling different cases. Once the matcher is
created, you can use pattern-matching functions like
when
to define
how different values should be processed.
Example (Matching Numbers and Strings)
import { Match } from "effect"
// Create a matcher for values that are either strings or numbers
//
// ┌─── (u: string | number) => string
// ▼
const match = Match.type<string | number>().pipe(
// Match when the value is a number
Match.when(Match.number, (n) => `number: ${n}`),
// Match when the value is a string
Match.when(Match.string, (s) => `string: ${s}`),
// Ensure all possible cases are handled
Match.exhaustive
)
console.log(match(0))
// Output: "number: 0"
console.log(match("hello"))
// Output: "string: hello"
type: <function (type parameter) I in <I>(): Matcher<I, Types.Without<never>, I, never, never>I>() => 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>(): Matcher<I, Types.Without<never>, I, never, never>I, Types.interface Types.Without<out X>Represents a filter that excludes specific types from a union.
Details
Without is used internally to track which types should be excluded
from consideration during pattern matching. It helps implement the
type-level logic for Match.not and other exclusion operations.
Example (Tracking excluded types)
import { Match } from "effect"
// Without is used internally when you write:
Match.type<string | number | boolean>().pipe(
Match.not(Match.string, (value) => `not string: ${value}`),
// At this point, type system uses Without<string> to track exclusion
Match.orElse(() => "was a string")
)
Without<never>, function (type parameter) I in <I>(): Matcher<I, Types.Without<never>, I, never, never>I, never, never> = import internalinternal.const type: <I>() => Matcher<
I,
Types.Without<never>,
I,
never,
never
>
type