ValueMatcher<Input, Filters, Remaining, Result, Provided, Return>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"export interface 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<in function (type parameter) Input in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Input, function (type parameter) Filters in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Filters, out function (type parameter) Remaining in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Remaining, out function (type parameter) Result in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Result, function (type parameter) Provided in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Provided, out function (type parameter) Return in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Return = any>
extends Pipeable
{
readonly ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>._tag: "ValueMatcher"_tag: "ValueMatcher"
readonly [const TypeId: "~effect/match/Match/Matcher"TypeId]: {
readonly _input: T.Contravariant<Input>_input: import TT.type Contravariant<A> = (_: A) => voidFunction-type alias encoding contravariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter contravariant in input
position.
Details
Contravariant<A> is assignable to Contravariant<B> when B extends A,
following the supertype direction.
Example (Defining a contravariant phantom type)
import type { Types } from "effect"
interface Consumer<T> {
readonly _phantom: Types.Contravariant<T>
readonly accept: (value: T) => void
}
Namespace for
Contravariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Contravariant.
Contravariant<function (type parameter) Input in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Input>
readonly _filters: T.Covariant<Filters>_filters: import TT.type Covariant<A> = (_: never) => AFunction-type alias encoding covariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter covariant in output
position.
Details
Covariant<A> is assignable to Covariant<B> when A extends B, following
the subtype direction.
Example (Defining a covariant phantom type)
import type { Types } from "effect"
interface Producer<T> {
readonly _phantom: Types.Covariant<T>
readonly get: () => T
}
Namespace for
Covariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Covariant.
Covariant<function (type parameter) Filters in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Filters>
readonly _result: T.Covariant<Result>_result: import TT.type Covariant<A> = (_: never) => AFunction-type alias encoding covariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter covariant in output
position.
Details
Covariant<A> is assignable to Covariant<B> when A extends B, following
the subtype direction.
Example (Defining a covariant phantom type)
import type { Types } from "effect"
interface Producer<T> {
readonly _phantom: Types.Covariant<T>
readonly get: () => T
}
Namespace for
Covariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Covariant.
Covariant<function (type parameter) Result in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Result>
readonly _return: T.Covariant<Return>_return: import TT.type Covariant<A> = (_: never) => AFunction-type alias encoding covariant variance for a phantom type
parameter.
When to use
Use as a phantom field type to make a type parameter covariant in output
position.
Details
Covariant<A> is assignable to Covariant<B> when A extends B, following
the subtype direction.
Example (Defining a covariant phantom type)
import type { Types } from "effect"
interface Producer<T> {
readonly _phantom: Types.Covariant<T>
readonly get: () => T
}
Namespace for
Covariant
-related utilities.
When to use
Use when referring to type-level helpers nested under Covariant.
Covariant<function (type parameter) Return in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Return>
}
readonly ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.provided: Providedprovided: function (type parameter) Provided in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Provided
readonly ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.value: Result.Result<Provided, Remaining>value: import ResultResult.type Result<A, E = never> = Result.Success<A, E> | Result.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<function (type parameter) Provided in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Provided, function (type parameter) Remaining in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>Remaining>
ValueMatcher<I, R, RA, A, Pr>(_case: Case): ValueMatcher<I, R, RA, A, Pr>add<function (type parameter) I in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.add<I, R, RA, A, Pr>(_case: Case): ValueMatcher<I, R, RA, A, Pr>I, function (type parameter) R in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.add<I, R, RA, A, Pr>(_case: Case): ValueMatcher<I, R, RA, A, Pr>R, function (type parameter) RA in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.add<I, R, RA, A, Pr>(_case: Case): ValueMatcher<I, R, RA, A, Pr>RA, function (type parameter) A in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.add<I, R, RA, A, Pr>(_case: Case): ValueMatcher<I, R, RA, A, Pr>A, function (type parameter) Pr in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.add<I, R, RA, A, Pr>(_case: Case): ValueMatcher<I, R, RA, A, Pr>Pr>(_case: Case_case: type Case = When | NotRepresents a single pattern matching case.
When to use
Use as the common public type for code that needs to inspect, store, or pass
either positive or negative pattern matching cases.
Details
A Case can be either a positive match (When) or a negative match (Not).
Cases are the building blocks of pattern matching logic and determine
how values are tested and transformed.
Case): 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) I in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.add<I, R, RA, A, Pr>(_case: Case): ValueMatcher<I, R, RA, A, Pr>I, function (type parameter) R in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.add<I, R, RA, A, Pr>(_case: Case): ValueMatcher<I, R, RA, A, Pr>R, function (type parameter) RA in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.add<I, R, RA, A, Pr>(_case: Case): ValueMatcher<I, R, RA, A, Pr>RA, function (type parameter) A in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.add<I, R, RA, A, Pr>(_case: Case): ValueMatcher<I, R, RA, A, Pr>A, function (type parameter) Pr in ValueMatcher<in Input, Filters, out Remaining, out Result, Provided, out Return = any>.add<I, R, RA, A, Pr>(_case: Case): ValueMatcher<I, R, RA, A, Pr>Pr>
}