Matcher<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"export type 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) Input in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Input, function (type parameter) Filters in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Filters, function (type parameter) RemainingApplied in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>RemainingApplied, function (type parameter) Result in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Result, function (type parameter) Provided in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Provided, function (type parameter) Return in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Return = any> =
| interface TypeMatcher<in Input, out Filters, out Remaining, out Result, out Return = any>Represents a pattern matcher that operates on types rather than specific values.
Details
A TypeMatcher is created when using Match.type<T>() and allows you to define
patterns that will be applied to values of the specified type. It maintains
type-level information about the input type, applied filters, remaining cases,
and expected results.
Example (Creating a type matcher)
import { Match } from "effect"
// Create a TypeMatcher for string | number
const matcher = Match.type<string | number>().pipe(
Match.when(Match.string, (s) => `String: ${s}`),
Match.when(Match.number, (n) => `Number: ${n}`),
Match.exhaustive
)
console.log(matcher("hello")) // "String: hello"
console.log(matcher(42)) // "Number: 42"
TypeMatcher<function (type parameter) Input in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Input, function (type parameter) Filters in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Filters, function (type parameter) RemainingApplied in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>RemainingApplied, function (type parameter) Result in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Result, function (type parameter) Return in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Return>
| interface ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Represents a pattern matcher that operates on a specific provided value.
Details
A ValueMatcher is created when using Match.value(someValue) and contains
the actual value to be matched against. It tracks both the provided value
and the result of applying patterns to determine matches.
Example (Creating a value matcher)
import { Match } from "effect"
const input = { type: "user", name: "Alice", age: 30 }
// Create a ValueMatcher for the specific input
const result = Match.value(input).pipe(
Match.when({ type: "user" }, (user) => `User: ${user.name}`),
Match.when({ type: "admin" }, (admin) => `Admin: ${admin.name}`),
Match.orElse(() => "Unknown type")
)
console.log(result) // "User: Alice"
ValueMatcher<function (type parameter) Input in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Input, function (type parameter) Filters in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Filters, function (type parameter) RemainingApplied in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>RemainingApplied, function (type parameter) Result in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Result, function (type parameter) Provided in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Provided, function (type parameter) Return in type Matcher<Input, Filters, RemainingApplied, Result, Provided, Return = any>Return>