Skip to content

Pattern Matching

Pattern matching is a method that allows developers to handle intricate conditions within a single, concise expression. It simplifies code, making it more concise and easier to understand. Additionally, it includes a process called exhaustiveness checking, which helps to ensure that no possible case has been overlooked.

Originating from functional programming languages, pattern matching stands as a powerful technique for code branching. It often offers a more potent and less verbose solution compared to imperative alternatives such as if/else or switch statements, particularly when dealing with complex conditions.

Although not yet a native feature in JavaScript, there’s an ongoing tc39 proposal in its early stages to introduce pattern matching to JavaScript. However, this proposal is at stage 1 and might take several years to be implemented. Nonetheless, developers can implement pattern matching in their codebase. The effect/Match module provides a reliable, type-safe pattern matching implementation that is available for immediate use.

Creating a Matcher involves using the type constructor function with a specified type. This sets the foundation for pattern matching against that particular type. Once the Matcher is established, developers can employ various combinators like when, not, and tag to define patterns that the Matcher will check against.

Example

1
import {
import Match
Match
} from "effect"
2
3
const
const match: (u: { a: number; } | { b: string; }) => string | number
match
=
import Match
Match
.
const type: <{ a: number; } | { b: string; }>() => Match.Matcher<{ a: number; } | { b: string; }, Match.Types.Without<never>, { a: number; } | { b: string; }, never, never, any>
type
<{
(property) a: number
a
: number } | {
(property) b: string
b
: string }>().
(method) Pipeable.pipe<Match.Matcher<{ a: number; } | { b: string; }, Match.Types.Without<never>, { a: number; } | { b: string; }, never, never, any>, Match.Matcher<{ a: number; } | { b: string; }, ... 4 more ..., any>, Match.Matcher<...>, (u: { ...; } | { ...; }) => string | number>(this: Match.Matcher<...>, ab: (_: Match.Matcher<...>) => Match.Matcher<...>, bc: (_: Match.Matcher<...>) => Match.Matcher<...>, cd: (_: Match.Matcher<...>) => (u: { ...; } | { ...; }) => string | number): (u: { ...; } | { ...; }) => string | number (+21 overloads)
pipe
(
4
import Match
Match
.
const when: <{ a: number; } | { b: string; }, { readonly a: Refinement<unknown, number>; }, any, (_: { a: number; }) => number>(pattern: { readonly a: Refinement<unknown, number>; }, f: (_: { a: number; }) => number) => <I, F, A, Pr>(self: Match.Matcher<...>) => Match.Matcher<...>
when
({
(property) a: Refinement<unknown, number>
a
:
import Match
Match
.
const number: Refinement<unknown, number>
number
}, (
(parameter) _: { a: number; }
_
) =>
(parameter) _: { a: number; }
_
.
(property) a: number
a
),
5
import Match
Match
.
const when: <{ b: string; }, { readonly b: Refinement<unknown, string>; }, any, (_: { b: string; }) => string>(pattern: { readonly b: Refinement<unknown, string>; }, f: (_: { b: string; }) => string) => <I, F, A, Pr>(self: Match.Matcher<...>) => Match.Matcher<...>
when
({
(property) b: Refinement<unknown, string>
b
:
import Match
Match
.
const string: Refinement<unknown, string>
string
}, (
(parameter) _: { b: string; }
_
) =>
(parameter) _: { b: string; }
_
.
(property) b: string
b
),
6
import Match
Match
.
const exhaustive: <I, F, A, Pr, Ret>(self: Match.Matcher<I, F, never, A, Pr, Ret>) => [Pr] extends [never] ? (u: I) => Unify<A> : Unify<A>
exhaustive
7
)
8
9
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (u: { a: number; } | { b: string; }) => string | number
match
({
(property) a: number
a
: 0 })) // Output: 0
10
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (u: { a: number; } | { b: string; }) => string | number
match
({
(property) b: string
b
: "hello" })) // Output: "hello"

Let’s dissect what’s happening:

  • Match.type<{ a: number } | { b: string }>(): This creates a Matcher for objects that are either of type { a: number } or { b: string }.
  • Match.when({ a: Match.number }, (_) => _.a): This sets up a condition to match an object with a property a containing a number. If matched, it returns the value of property a.
  • Match.when({ b: Match.string }, (_) => _.b): This condition matches an object with a property b containing a string. If found, it returns the value of property b.
  • Match.exhaustive: This function ensures that all possible cases are considered and matched, making sure that no other unaccounted cases exist. It helps to prevent overlooking any potential scenario.

Finally, the match function is applied to test two different objects, { a: 0 } and { b: "hello" }. As per the defined conditions within the Matcher, it correctly matches the objects and provides the expected output based on the defined conditions.

In addition to defining a Matcher based on a specific type, developers can also create a Matcher directly from a value utilizing the value constructor function. This method allows matching patterns against the provided value.

Example

1
import {
import Match
Match
} from "effect"
2
3
const
const result: string
result
=
import Match
Match
.
const value: <{ readonly name: "John"; readonly age: 30; }>(i: { readonly name: "John"; readonly age: 30; }) => Match.Matcher<{ readonly name: "John"; readonly age: 30; }, Match.Types.Without<never>, { readonly name: "John"; readonly age: 30; }, never, { readonly name: "John"; readonly age: 30; }, any>
value
({
(property) name: "John"
name
: "John",
(property) age: 30
age
: 30 }).
(method) Pipeable.pipe<Match.Matcher<{ readonly name: "John"; readonly age: 30; }, Match.Types.Without<never>, { readonly name: "John"; readonly age: 30; }, never, { readonly name: "John"; readonly age: 30; }, any>, Match.Matcher<...>, string>(this: Match.Matcher<...>, ab: (_: Match.Matcher<...>) => Match.Matcher<...>, bc: (_: Match.Matcher<...>) => string): string (+21 overloads)
pipe
(
4
import Match
Match
.
const when: <{ readonly name: "John"; readonly age: 30; }, { readonly name: "John"; }, any, (user: { name: "John"; readonly age: 30; }) => string>(pattern: { readonly name: "John"; }, f: (user: { name: "John"; readonly age: 30; }) => string) => <I, F, A, Pr>(self: Match.Matcher<...>) => Match.Matcher<...>
when
(
5
{
(property) name: "John"
name
: "John" },
6
(
(parameter) user: { name: "John"; readonly age: 30; }
user
) => `${
(parameter) user: { name: "John"; readonly age: 30; }
user
.
(property) name: "John"
name
} is ${
(parameter) user: { name: "John"; readonly age: 30; }
user
.
(property) age: 30
age
} years old`
7
),
8
import Match
Match
.
const orElse: <never, any, () => string>(f: () => string) => <I, R, A, Pr>(self: Match.Matcher<I, R, never, A, Pr, any>) => [Pr] extends [never] ? (input: I) => Unify<...> : Unify<...>
orElse
(() => "Oh, not John")
9
)
10
11
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const result: string
result
) // Output: "John is 30 years old"

Here’s a breakdown of what’s happening:

  • Match.value({ name: "John", age: 30 }): This initializes a Matcher using the provided value { name: "John", age: 30 }.
  • Match.when({ name: "John" }, (user) => ...: It establishes a condition to match the object having the property name set to “John”. If the condition is met, it constructs a string indicating the name and age of the user.
  • Match.orElse(() => "Oh, not John"): In the absence of a match with the name “John,” this provides a default output.

Predicates allow the testing of values against specific conditions. It helps in creating rules or conditions for the data being evaluated.

1
import {
import Match
Match
} from "effect"
2
3
const
const match: (input: { age: number; }) => string
match
=
import Match
Match
.
const type: <{ age: number; }>() => Match.Matcher<{ age: number; }, Match.Types.Without<never>, { age: number; }, never, never, any>
type
<{
(property) age: number
age
: number }>().
(method) Pipeable.pipe<Match.Matcher<{ age: number; }, Match.Types.Without<never>, { age: number; }, never, never, any>, Match.Matcher<{ age: number; }, Match.Types.Without<{ readonly age: never; }>, { age: number; }, string, never, any>, (input: { ...; }) => string>(this: Match.Matcher<...>, ab: (_: Match.Matcher<...>) => Match.Matcher<...>, bc: (_: Match.Matcher<...>) => (input: { ...; }) => string): (input: { ...; }) => string (+21 overloads)
pipe
(
4
import Match
Match
.
const when: <{ age: number; }, { readonly age: (age: number) => boolean; }, any, (user: { age: number; }) => string>(pattern: { readonly age: (age: number) => boolean; }, f: (user: { age: number; }) => string) => <I, F, A, Pr>(self: Match.Matcher<...>) => Match.Matcher<...>
when
({
(property) age: (age: number) => boolean
age
: (
(parameter) age: number
age
) =>
(parameter) age: number
age
>= 5 }, (
(parameter) user: { age: number; }
user
) => `Age: ${
(parameter) user: { age: number; }
user
.
(property) age: number
age
}`),
5
import Match
Match
.
const orElse: <{ age: number; }, any, (user: { age: number; }) => string>(f: (user: { age: number; }) => string) => <I, R, A, Pr>(self: Match.Matcher<I, R, { age: number; }, A, Pr, any>) => [...] extends [...] ? (input: I) => Unify<...> : Unify<...>
orElse
((
(parameter) user: { age: number; }
user
) => `${
(parameter) user: { age: number; }
user
.
(property) age: number
age
} is too young`)
6
)
7
8
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (input: { age: number; }) => string
match
({
(property) age: number
age
: 5 })) // Output: "Age: 5"
9
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (input: { age: number; }) => string
match
({
(property) age: number
age
: 4 })) // Output: "4 is too young"

not allows for excluding a specific value while matching other conditions.

1
import {
import Match
Match
} from "effect"
2
3
const
const match: (input: string | number) => string
match
=
import Match
Match
.
const type: <string | number>() => Match.Matcher<string | number, Match.Types.Without<never>, string | number, never, never, any>
type
<string | number>().
(method) Pipeable.pipe<Match.Matcher<string | number, Match.Types.Without<never>, string | number, never, never, any>, Match.Matcher<string | number, Match.Types.Only<"hi">, "hi", string, never, any>, (input: string | number) => string>(this: Match.Matcher<...>, ab: (_: Match.Matcher<...>) => Match.Matcher<...>, bc: (_: Match.Matcher<...>) => (input: string | number) => string): (input: string | number) => string (+21 overloads)
pipe
(
4
import Match
Match
.
const not: <string | number, "hi", any, (_: string | number) => string>(pattern: "hi", f: (_: string | number) => string) => <I, F, A, Pr>(self: Match.Matcher<I, F, string | number, A, Pr, any>) => Match.Matcher<...>
not
("hi", (
(parameter) _: string | number
_
) => "a"),
5
import Match
Match
.
const orElse: <"hi", any, () => string>(f: () => string) => <I, R, A, Pr>(self: Match.Matcher<I, R, "hi", A, Pr, any>) => [Pr] extends [never] ? (input: I) => Unify<...> : Unify<...>
orElse
(() => "b")
6
)
7
8
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (input: string | number) => string
match
("hello")) // Output: "a"
9
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (input: string | number) => string
match
("hi")) // Output: "b"

The tag function enables pattern matching against the tag within a Discriminated Union.

1
import {
import Match
Match
,
import Either
Either
} from "effect"
2
3
const
const match: (u: Either.Either<number, string>) => string | number
match
=
import Match
Match
.
const type: <Either.Either<number, string>>() => Match.Matcher<Either.Either<number, string>, Match.Types.Without<never>, Either.Either<number, string>, never, never, any>
type
<
import Either
Either
.
type Either<R, L = never> = Either.Left<L, R> | Either.Right<L, R> namespace Either
Either
<number, string>>().
(method) Pipeable.pipe<Match.Matcher<Either.Either<number, string>, Match.Types.Without<never>, Either.Either<number, string>, never, never, any>, Match.Matcher<Either.Either<number, string>, ... 4 more ..., any>, Match.Matcher<...>, (u: Either.Either<...>) => string | number>(this: Match.Matcher<...>, ab: (_: Match.Matcher<...>) => Match.Matcher<...>, bc: (_: Match.Matcher<...>) => Match.Matcher<...>, cd: (_: Match.Matcher<...>) => (u: Either.Either<...>) => string | number): (u: Either.Either<...>) => string | number (+21 overloads)
pipe
(
4
import Match
Match
.
const tag: <Either.Either<number, string>, "Right", any, number>(...pattern: [first: "Right", ...values: "Right"[], f: (_: Either.Right<string, number>) => number]) => <I, F, A, Pr>(self: Match.Matcher<I, ... 4 more ..., any>) => Match.Matcher<...>
tag
("Right", (
(parameter) _: Either.Right<string, number>
_
) =>
(parameter) _: Either.Right<string, number>
_
.
(property) Right<string, number>.right: number
right
),
5
import Match
Match
.
const tag: <Either.Left<string, number>, "Left", any, string>(...pattern: [first: "Left", ...values: "Left"[], f: (_: Either.Left<string, number>) => string]) => <I, F, A, Pr>(self: Match.Matcher<I, F, Either.Left<...>, A, Pr, any>) => Match.Matcher<...>
tag
("Left", (
(parameter) _: Either.Left<string, number>
_
) =>
(parameter) _: Either.Left<string, number>
_
.
(property) Left<string, number>.left: string
left
),
6
import Match
Match
.
const exhaustive: <I, F, A, Pr, Ret>(self: Match.Matcher<I, F, never, A, Pr, Ret>) => [Pr] extends [never] ? (u: I) => Unify<A> : Unify<A>
exhaustive
7
)
8
9
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (u: Either.Either<number, string>) => string | number
match
(
import Either
Either
.
const right: <number>(right: number) => Either.Either<number, never>

Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias of this structure.

right
(123))) // Output: 123
10
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (u: Either.Either<number, string>) => string | number
match
(
import Either
Either
.
const left: <string>(left: string) => Either.Either<never, string>

Constructs a new `Either` holding a `Left` value. This usually represents a failure, due to the right-bias of this structure.

left
("Oh no!"))) // Output: "Oh no!"

The exhaustive transformation serves as an endpoint within the matching process, ensuring all potential matches have been considered. It results in returning the match (for Match.value) or the evaluation function (for Match.type).

1
import {
import Match
Match
,
import Either
Either
} from "effect"
2
3
const
const result: never
result
=
import Match
Match
.
const value: <Either.Either<number, never>>(i: Either.Either<number, never>) => Match.Matcher<Either.Either<number, never>, Match.Types.Without<never>, Either.Either<number, never>, never, Either.Either<...>, any>
value
(
import Either
Either
.
const right: <number>(right: number) => Either.Either<number, never>

Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias of this structure.

right
(0)).
(method) Pipeable.pipe<Match.Matcher<Either.Either<number, never>, Match.Types.Without<never>, Either.Either<number, never>, never, Either.Either<number, never>, any>, never, never>(this: Match.Matcher<...>, ab: (_: Match.Matcher<...>) => never, bc: (_: never) => never): never (+21 overloads)
pipe
(
4
import Match
Match
.
const when: <Either.Either<number, never>, { readonly _tag: "Right"; }, any, (_: { _tag: "Right"; readonly [TypeId]: { readonly _R: Covariant<number>; readonly _L: Covariant<never>; }; ... 14 more ...; readonly right: number; }) => number>(pattern: { ...; }, f: (_: { _tag: "Right"; readonly [TypeId]: { readonly _R: Covariant<number>; readonly _L: Covariant<never>; }; ... 14 more ...; readonly right: number; }) => number) => <I, F, A, Pr>(self: Match.Matcher<...>) => Match.Matcher<...>
when
({
(property) _tag: "Right"
_tag
: "Right" }, (
(parameter) _: { _tag: "Right"; readonly [TypeId]: { readonly _R: Covariant<number>; readonly _L: Covariant<never>; }; [Unify.typeSymbol]?: unknown; [Unify.unifySymbol]?: Either.EitherUnify<...>; ... 12 more ...; readonly right: number; }
_
) =>
(parameter) _: { _tag: "Right"; readonly [TypeId]: { readonly _R: Covariant<number>; readonly _L: Covariant<never>; }; [Unify.typeSymbol]?: unknown; [Unify.unifySymbol]?: Either.EitherUnify<...>; ... 12 more ...; readonly right: number; }
_
.
(property) right: number
right
),
5
// @ts-expect-error
6
import Match
Match
.
const exhaustive: <I, F, A, Pr, Ret>(self: Match.Matcher<I, F, never, A, Pr, Ret>) => [Pr] extends [never] ? (u: I) => Unify<A> : Unify<A>
exhaustive
7
// TypeError! Type 'Left<never, number>' is not assignable to type 'never'
8
)

The orElse transformation signifies the conclusion of the matching process, offering a fallback value when no specific patterns match. It returns the match (for Match.value) or the evaluation function (for Match.type).

1
import {
import Match
Match
} from "effect"
2
3
const
const match: (input: string | number) => string
match
=
import Match
Match
.
const type: <string | number>() => Match.Matcher<string | number, Match.Types.Without<never>, string | number, never, never, any>
type
<string | number>().
(method) Pipeable.pipe<Match.Matcher<string | number, Match.Types.Without<never>, string | number, never, never, any>, Match.Matcher<string | number, Match.Types.Without<"hi">, string | number, string, never, any>, (input: string | number) => string>(this: Match.Matcher<...>, ab: (_: Match.Matcher<...>) => Match.Matcher<...>, bc: (_: Match.Matcher<...>) => (input: string | number) => string): (input: string | number) => string (+21 overloads)
pipe
(
4
import Match
Match
.
const when: <string | number, "hi", any, (_: "hi") => string>(pattern: "hi", f: (_: "hi") => string) => <I, F, A, Pr>(self: Match.Matcher<I, F, string | number, A, Pr, any>) => Match.Matcher<...>
when
("hi", (
(parameter) _: "hi"
_
) => "hello"),
5
import Match
Match
.
const orElse: <string | number, any, () => string>(f: () => string) => <I, R, A, Pr>(self: Match.Matcher<I, R, string | number, A, Pr, any>) => [Pr] extends [...] ? (input: I) => Unify<...> : Unify<...>
orElse
(() => "I literally do not understand")
6
)
7
8
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (input: string | number) => string
match
("hi")) // Output: "hello"
9
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (input: string | number) => string
match
("hello")) // Output: "I literally do not understand"

The option transformation returns the result encapsulated within an Option. When the match succeeds, it represents the result as Some, and when there’s no match, it signifies the absence of a value with None.

1
import {
import Match
Match
,
import Either
Either
} from "effect"
2
3
const
const result: Option<number>
result
=
import Match
Match
.
const value: <Either.Either<number, never>>(i: Either.Either<number, never>) => Match.Matcher<Either.Either<number, never>, Match.Types.Without<never>, Either.Either<number, never>, never, Either.Either<...>, any>
value
(
import Either
Either
.
const right: <number>(right: number) => Either.Either<number, never>

Constructs a new `Either` holding a `Right` value. This usually represents a successful value due to the right bias of this structure.

right
(0)).
(method) Pipeable.pipe<Match.Matcher<Either.Either<number, never>, Match.Types.Without<never>, Either.Either<number, never>, never, Either.Either<number, never>, any>, Match.Matcher<...>, Option<...>>(this: Match.Matcher<...>, ab: (_: Match.Matcher<...>) => Match.Matcher<...>, bc: (_: Match.Matcher<...>) => Option<...>): Option<...> (+21 overloads)
pipe
(
4
import Match
Match
.
const when: <Either.Either<number, never>, { readonly _tag: "Right"; }, any, (_: { _tag: "Right"; readonly [TypeId]: { readonly _R: Covariant<number>; readonly _L: Covariant<never>; }; ... 14 more ...; readonly right: number; }) => number>(pattern: { ...; }, f: (_: { _tag: "Right"; readonly [TypeId]: { readonly _R: Covariant<number>; readonly _L: Covariant<never>; }; ... 14 more ...; readonly right: number; }) => number) => <I, F, A, Pr>(self: Match.Matcher<...>) => Match.Matcher<...>
when
({
(property) _tag: "Right"
_tag
: "Right" }, (
(parameter) _: { _tag: "Right"; readonly [TypeId]: { readonly _R: Covariant<number>; readonly _L: Covariant<never>; }; [Unify.typeSymbol]?: unknown; [Unify.unifySymbol]?: Either.EitherUnify<...>; ... 12 more ...; readonly right: number; }
_
) =>
(parameter) _: { _tag: "Right"; readonly [TypeId]: { readonly _R: Covariant<number>; readonly _L: Covariant<never>; }; [Unify.typeSymbol]?: unknown; [Unify.unifySymbol]?: Either.EitherUnify<...>; ... 12 more ...; readonly right: number; }
_
.
(property) right: number
right
),
5
import Match
Match
.
const option: <I, F, R, A, Pr, Ret>(self: Match.Matcher<I, F, R, A, Pr, Ret>) => [Pr] extends [never] ? (input: I) => Option<Unify<A>> : Option<Unify<A>>
option
6
)
7
8
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const result: Option<number>
result
) // Output: { _id: 'Option', _tag: 'Some', value: 0 }

The either transformation might match a value, returning an Either following the format Either<MatchResult, NoMatchResult>.

1
import {
import Match
Match
} from "effect"
2
3
const
const match: (input: string) => Either<number, string>
match
=
import Match
Match
.
const type: <string>() => Match.Matcher<string, Match.Types.Without<never>, string, never, never, any>
type
<string>().
(method) Pipeable.pipe<Match.Matcher<string, Match.Types.Without<never>, string, never, never, any>, Match.Matcher<string, Match.Types.Without<"hi">, string, number, never, any>, (input: string) => Either<...>>(this: Match.Matcher<...>, ab: (_: Match.Matcher<...>) => Match.Matcher<...>, bc: (_: Match.Matcher<...>) => (input: string) => Either<...>): (input: string) => Either<...> (+21 overloads)
pipe
(
4
import Match
Match
.
const when: <string, "hi", any, (_: "hi") => number>(pattern: "hi", f: (_: "hi") => number) => <I, F, A, Pr>(self: Match.Matcher<I, F, string, A, Pr, any>) => Match.Matcher<I, ... 4 more ..., any>
when
("hi", (
(parameter) _: "hi"
_
) =>
(parameter) _: "hi"
_
.
(property) String.length: number

Returns the length of a String object.

length
),
5
import Match
Match
.
const either: <I, F, R, A, Pr, Ret>(self: Match.Matcher<I, F, R, A, Pr, Ret>) => [Pr] extends [never] ? (input: I) => Either<Unify<A>, R> : Either<Unify<A>, R>
either
6
)
7
8
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (input: string) => Either<number, string>
match
("hi")) // Output: { _id: 'Either', _tag: 'Right', right: 2 }
9
namespace console var console: Console

The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream. * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module. _**Warning**_: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js console.log('hello world'); // Prints: hello world, to stdout console.log('hello %s', 'world'); // Prints: hello world, to stdout console.error(new Error('Whoops, something bad happened')); // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name = 'Will Robinson'; console.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to stderr ``` Example using the `Console` class: ```js const out = getStreamSomehow(); const err = getStreamSomehow(); const myConsole = new console.Console(out, err); myConsole.log('hello world'); // Prints: hello world, to out myConsole.log('hello %s', 'world'); // Prints: hello world, to out myConsole.error(new Error('Whoops, something bad happened')); // Prints: [Error: Whoops, something bad happened], to err const name = 'Will Robinson'; myConsole.warn(`Danger ${name}! Danger!`); // Prints: Danger Will Robinson! Danger!, to err ```

console
.
(method) Console.log(message?: any, ...optionalParams: any[]): void

Prints to `stdout` with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js const count = 5; console.log('count: %d', count); // Prints: count: 5, to stdout console.log('count:', count); // Prints: count: 5, to stdout ``` See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const match: (input: string) => Either<number, string>
match
("shigidigi")) // Output: { _id: 'Either', _tag: 'Left', left: 'shigidigi' }