<const I>(i: I): Matcher<I, Types.Without<never>, I, never, I>Creates a matcher from a specific value.
When to use
Use to match one concrete input immediately.
Details
This function allows you to define a Matcher directly from a given value,
rather than from a type. This is useful when working with known values,
enabling structured pattern matching on objects, primitives, or any data
structure.
Once the matcher is created, you can use pattern-matching functions like when to define how different cases should be handled.
Example (Matching an Object by Property)
import { Match } from "effect"
const input = { name: "John", age: 30 }
// Create a matcher for the specific object
const result = Match.value(input).pipe(
// Match when the 'name' property is "John"
Match.when(
{ name: "John" },
(user) => `${user.name} is ${user.age} years old`
),
// Provide a fallback if no match is found
Match.orElse(() => "Oh, not John")
)
console.log(result)
// Output: "John is 30 years old"export const const value: <I>(
i: I
) => Matcher<I, Types.Without<never>, I, never, I>
Creates a matcher from a specific value.
When to use
Use to match one concrete input immediately.
Details
This function allows you to define a Matcher directly from a given value,
rather than from a type. This is useful when working with known values,
enabling structured pattern matching on objects, primitives, or any data
structure.
Once the matcher is created, you can use pattern-matching functions like
when
to define how different cases should be handled.
Example (Matching an Object by Property)
import { Match } from "effect"
const input = { name: "John", age: 30 }
// Create a matcher for the specific object
const result = Match.value(input).pipe(
// Match when the 'name' property is "John"
Match.when(
{ name: "John" },
(user) => `${user.name} is ${user.age} years old`
),
// Provide a fallback if no match is found
Match.orElse(() => "Oh, not John")
)
console.log(result)
// Output: "John is 30 years old"
value: <const function (type parameter) I in <const I>(i: I): Matcher<I, Types.Without<never>, I, never, I>I>(
i: const Ii: function (type parameter) I in <const I>(i: I): Matcher<I, Types.Without<never>, I, never, I>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 <const I>(i: I): Matcher<I, Types.Without<never>, I, never, I>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 <const I>(i: I): Matcher<I, Types.Without<never>, I, never, I>I, never, function (type parameter) I in <const I>(i: I): Matcher<I, Types.Without<never>, I, never, I>I> = import internalinternal.const value: <I>(
i: I
) => Matcher<I, Types.Without<never>, I, never, I>
value