Skip to content

Getting Started with Micro

The Micro module in Effect is designed as a lighter alternative to the standard Effect module, tailored for situations where it is beneficial to reduce the bundle size.

This module is standalone and does not include more complex functionalities such as Layer, Ref, Queue, and Deferred. This feature set makes Micro especially suitable for libraries that wish to utilize Effect functionalities while keeping the bundle size to a minimum, particularly for those aiming to provide Promise-based APIs.

Micro also supports use cases where a client application uses Micro, and a server employs the full suite of Effect features, maintaining both compatibility and logical consistency across various application components.

Integrating Micro adds a minimal footprint to your bundle, starting at 5kb gzipped, which may increase depending on the features you use.

Before you start, make sure you have completed the following setup:

Install the effect library in your project. If it is not already installed, you can add it using npm with the following command:

Terminal window
npm install effect

Micro is a component of the Effect library and can be imported similarly to any other module in your TypeScript project:

import * as Micro from "effect/Micro"

This import statement allows you to access all functionalities of Micro, enabling you to use its features in your application.

The Micro type uses three type parameters:

Micro<Success, Error, Requirements>

which mirror those of the Effect type:

  • Success. Represents the type of value that an effect can succeed with when executed. If this type parameter is void, it means the effect produces no useful information, while if it is never, it means the effect runs forever (or until failure).
  • Error. Represents the expected errors that can occur when executing an effect. If this type parameter is never, it means the effect cannot fail, because there are no values of type never.
  • Requirements. Represents the contextual data required by the effect to be executed. This data is stored in a collection named Context. If this type parameter is never, it means the effect has no requirements and the Context collection is empty.

The MicroExit type is designed to capture the outcome of a Micro computation. It uses the Either data type to distinguish between successful outcomes and failures:

type MicroExit<A, E = never> = Either<A, MicroCause<E>>

The MicroCause type represents the possible causes of an effect’s failure.

MicroCause consists of three specific types:

type MicroCause<E> = Die | Fail<E> | Interrupt
Failure TypeDescription
DieIndicates an unforeseen defect that wasn’t planned for in the system’s logic.
Fail<E>Covers anticipated errors that are recognized and typically handled within the application.
InterruptSignifies an operation that has been purposefully stopped.

In this tutorial, we’ll demonstrate how to wrap a Promise-based API using the Micro library from Effect. We’ll use a simple example where we interact with a hypothetical weather forecasting API. The goal is to encapsulate the asynchronous API call within Micro’s structured error handling and execution flow.

Step 1: Create a Promise-based API Function

First, let’s define a simple Promise-based function that simulates fetching weather data from an external service.

1
function
function fetchWeather(city: string): Promise<string>
fetchWeather
(
(parameter) city: string
city
: string):
interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<string> {
2
return new
var Promise: PromiseConstructor new <string>(executor: (resolve: (value: string | PromiseLike<string>) => void, reject: (reason?: any) => void) => void) => Promise<string>

Creates a new Promise.

Promise
((
(parameter) resolve: (value: string | PromiseLike<string>) => void
resolve
,
(parameter) reject: (reason?: any) => void
reject
) => {
3
function setTimeout<[]>(callback: () => void, ms?: number): NodeJS.Timeout (+1 overload) namespace setTimeout

Schedules execution of a one-time `callback` after `delay` milliseconds. The `callback` will likely not be invoked in precisely `delay` milliseconds. Node.js makes no guarantees about the exact timing of when callbacks will fire, nor of their ordering. The callback will be called as close as possible to the time specified. When `delay` is larger than `2147483647` or less than `1`, the `delay` will be set to `1`. Non-integer delays are truncated to an integer. If `callback` is not a function, a `TypeError` will be thrown. This method has a custom variant for promises that is available using `timersPromises.setTimeout()`.

setTimeout
(() => {
4
if (
(parameter) city: string
city
=== "London") {
5
(parameter) resolve: (value: string | PromiseLike<string>) => void
resolve
("Sunny")
6
} else {
7
(parameter) reject: (reason?: any) => void
reject
(new
var Error: ErrorConstructor new (message?: string) => Error
Error
("Weather data not found for this location"))
8
}
9
}, 1_000)
10
})
11
}

Step 2: Wrap the Promise with Micro

Next, we’ll wrap our fetchWeather function using Micro to handle both successful and failed Promise outcomes.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
function
function fetchWeather(city: string): Promise<string>
fetchWeather
(
(parameter) city: string
city
: string):
interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<string> {
4
return new
var Promise: PromiseConstructor new <string>(executor: (resolve: (value: string | PromiseLike<string>) => void, reject: (reason?: any) => void) => void) => Promise<string>

Creates a new Promise.

Promise
((
(parameter) resolve: (value: string | PromiseLike<string>) => void
resolve
,
(parameter) reject: (reason?: any) => void
reject
) => {
5
function setTimeout<[]>(callback: () => void, ms?: number): NodeJS.Timeout (+1 overload) namespace setTimeout

Schedules execution of a one-time `callback` after `delay` milliseconds. The `callback` will likely not be invoked in precisely `delay` milliseconds. Node.js makes no guarantees about the exact timing of when callbacks will fire, nor of their ordering. The callback will be called as close as possible to the time specified. When `delay` is larger than `2147483647` or less than `1`, the `delay` will be set to `1`. Non-integer delays are truncated to an integer. If `callback` is not a function, a `TypeError` will be thrown. This method has a custom variant for promises that is available using `timersPromises.setTimeout()`.

setTimeout
(() => {
6
if (
(parameter) city: string
city
=== "London") {
7
(parameter) resolve: (value: string | PromiseLike<string>) => void
resolve
("Sunny")
8
} else {
9
(parameter) reject: (reason?: any) => void
reject
(new
var Error: ErrorConstructor new (message?: string) => Error
Error
("Weather data not found for this location"))
10
}
11
}, 1_000)
12
})
13
}
14
15
function
function getWeather(city: string): Micro.Micro<string, never, never>
getWeather
(
(parameter) city: string
city
: string) {
16
return
import Micro
Micro
.
const promise: <string>(evaluate: (signal: AbortSignal) => PromiseLike<string>) => Micro.Micro<string, never, never>

Wrap a `Promise` into a `Micro` effect. Any errors will result in a `CauseDie`.

promise
(() =>
function fetchWeather(city: string): Promise<string>
fetchWeather
(
(parameter) city: string
city
))
17
}

Here, Micro.promise is used to convert the Promise returned by fetchWeather into a Micro effect.

Step 3: Running the Micro Effect

After wrapping our function, we need to execute the Micro effect and handle the results.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
function
function fetchWeather(city: string): Promise<string>
fetchWeather
(
(parameter) city: string
city
: string):
interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<string> {
4
return new
var Promise: PromiseConstructor new <string>(executor: (resolve: (value: string | PromiseLike<string>) => void, reject: (reason?: any) => void) => void) => Promise<string>

Creates a new Promise.

Promise
((
(parameter) resolve: (value: string | PromiseLike<string>) => void
resolve
,
(parameter) reject: (reason?: any) => void
reject
) => {
5
function setTimeout<[]>(callback: () => void, ms?: number): NodeJS.Timeout (+1 overload) namespace setTimeout

Schedules execution of a one-time `callback` after `delay` milliseconds. The `callback` will likely not be invoked in precisely `delay` milliseconds. Node.js makes no guarantees about the exact timing of when callbacks will fire, nor of their ordering. The callback will be called as close as possible to the time specified. When `delay` is larger than `2147483647` or less than `1`, the `delay` will be set to `1`. Non-integer delays are truncated to an integer. If `callback` is not a function, a `TypeError` will be thrown. This method has a custom variant for promises that is available using `timersPromises.setTimeout()`.

setTimeout
(() => {
6
if (
(parameter) city: string
city
=== "London") {
7
(parameter) resolve: (value: string | PromiseLike<string>) => void
resolve
("Sunny")
8
} else {
9
(parameter) reject: (reason?: any) => void
reject
(new
var Error: ErrorConstructor new (message?: string) => Error
Error
("Weather data not found for this location"))
10
}
11
}, 1_000)
12
})
13
}
14
15
function
function getWeather(city: string): Micro.Micro<string, never, never>
getWeather
(
(parameter) city: string
city
: string) {
16
return
import Micro
Micro
.
const promise: <string>(evaluate: (signal: AbortSignal) => PromiseLike<string>) => Micro.Micro<string, never, never>

Wrap a `Promise` into a `Micro` effect. Any errors will result in a `CauseDie`.

promise
(() =>
function fetchWeather(city: string): Promise<string>
fetchWeather
(
(parameter) city: string
city
))
17
}
18
19
const
const weatherEffect: Micro.Micro<string, never, never>
weatherEffect
=
function getWeather(city: string): Micro.Micro<string, never, never>
getWeather
("London")
20
21
import Micro
Micro
.
const runPromise: <string, never>(effect: Micro.Micro<string, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const weatherEffect: Micro.Micro<string, never, never>
weatherEffect
)
22
.
(method) Promise<string>.then<void, never>(onfulfilled?: ((value: string) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
((
(parameter) result: string
result
) =>
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
(`The weather in London is: ${
(parameter) result: string
result
}`))
23
.
(method) Promise<void>.catch<void>(onrejected?: ((reason: any) => void | PromiseLike<void>) | null | undefined): Promise<void>

Attaches a callback for only the rejection of the Promise.

catch
((
(parameter) error: any
error
) =>
24
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.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` 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 code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
(`Failed to fetch weather data: ${
(parameter) error: any
error
.
any
message
}`)
25
)
26
/*
27
Output:
28
The weather in London is: Sunny
29
*/

In this snippet, Micro.runPromise is used to execute the weatherEffect. It converts the Micro effect back into a Promise, making it easier to integrate with other Promise-based code or simply to manage asynchronous operations in a familiar way.

You can also use Micro.runPromiseExit to get more detailed information about the effect’s exit status:

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
function
function fetchWeather(city: string): Promise<string>
fetchWeather
(
(parameter) city: string
city
: string):
interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<string> {
4
return new
var Promise: PromiseConstructor new <string>(executor: (resolve: (value: string | PromiseLike<string>) => void, reject: (reason?: any) => void) => void) => Promise<string>

Creates a new Promise.

Promise
((
(parameter) resolve: (value: string | PromiseLike<string>) => void
resolve
,
(parameter) reject: (reason?: any) => void
reject
) => {
5
function setTimeout<[]>(callback: () => void, ms?: number): NodeJS.Timeout (+1 overload) namespace setTimeout

Schedules execution of a one-time `callback` after `delay` milliseconds. The `callback` will likely not be invoked in precisely `delay` milliseconds. Node.js makes no guarantees about the exact timing of when callbacks will fire, nor of their ordering. The callback will be called as close as possible to the time specified. When `delay` is larger than `2147483647` or less than `1`, the `delay` will be set to `1`. Non-integer delays are truncated to an integer. If `callback` is not a function, a `TypeError` will be thrown. This method has a custom variant for promises that is available using `timersPromises.setTimeout()`.

setTimeout
(() => {
6
if (
(parameter) city: string
city
=== "London") {
7
(parameter) resolve: (value: string | PromiseLike<string>) => void
resolve
("Sunny")
8
} else {
9
(parameter) reject: (reason?: any) => void
reject
(new
var Error: ErrorConstructor new (message?: string) => Error
Error
("Weather data not found for this location"))
10
}
11
}, 1_000)
12
})
13
}
14
15
function
function getWeather(city: string): Micro.Micro<string, never, never>
getWeather
(
(parameter) city: string
city
: string) {
16
return
import Micro
Micro
.
const promise: <string>(evaluate: (signal: AbortSignal) => PromiseLike<string>) => Micro.Micro<string, never, never>

Wrap a `Promise` into a `Micro` effect. Any errors will result in a `CauseDie`.

promise
(() =>
function fetchWeather(city: string): Promise<string>
fetchWeather
(
(parameter) city: string
city
))
17
}
18
19
const
const weatherEffect: Micro.Micro<string, never, never>
weatherEffect
=
function getWeather(city: string): Micro.Micro<string, never, never>
getWeather
("London")
20
21
import Micro
Micro
.
const runPromiseExit: <string, never>(effect: Micro.Micro<string, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const weatherEffect: Micro.Micro<string, never, never>
weatherEffect
).
(method) Promise<MicroExit<string, never>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<string, never>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
((
(parameter) exit: Micro.MicroExit<string, never>
exit
) =>
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
(
(parameter) exit: Micro.MicroExit<string, never>
exit
))
22
/*
23
Output:
24
{ _id: 'Either', _tag: 'Right', right: 'Sunny' }
25
*/

Step 4: Adding Error Handling

To further enhance the function, you might want to handle specific errors differently. Micro provides methods like Micro.tryPromise to handle anticipated errors gracefully.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
function
function fetchWeather(city: string): Promise<string>
fetchWeather
(
(parameter) city: string
city
: string):
interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<string> {
4
return new
var Promise: PromiseConstructor new <string>(executor: (resolve: (value: string | PromiseLike<string>) => void, reject: (reason?: any) => void) => void) => Promise<string>

Creates a new Promise.

Promise
((
(parameter) resolve: (value: string | PromiseLike<string>) => void
resolve
,
(parameter) reject: (reason?: any) => void
reject
) => {
5
function setTimeout<[]>(callback: () => void, ms?: number): NodeJS.Timeout (+1 overload) namespace setTimeout

Schedules execution of a one-time `callback` after `delay` milliseconds. The `callback` will likely not be invoked in precisely `delay` milliseconds. Node.js makes no guarantees about the exact timing of when callbacks will fire, nor of their ordering. The callback will be called as close as possible to the time specified. When `delay` is larger than `2147483647` or less than `1`, the `delay` will be set to `1`. Non-integer delays are truncated to an integer. If `callback` is not a function, a `TypeError` will be thrown. This method has a custom variant for promises that is available using `timersPromises.setTimeout()`.

setTimeout
(() => {
6
if (
(parameter) city: string
city
=== "London") {
7
(parameter) resolve: (value: string | PromiseLike<string>) => void
resolve
("Sunny")
8
} else {
9
(parameter) reject: (reason?: any) => void
reject
(new
var Error: ErrorConstructor new (message?: string) => Error
Error
("Weather data not found for this location"))
10
}
11
}, 1_000)
12
})
13
}
14
15
class
class WeatherError
WeatherError
{
16
readonly
(property) WeatherError._tag: "WeatherError"
_tag
= "WeatherError"
17
constructor(readonly
(property) WeatherError.message: string
message
: string) {}
18
}
19
20
function
function getWeather(city: string): Micro.Micro<string, WeatherError, never>
getWeather
(
(parameter) city: string
city
: string) {
21
return
import Micro
Micro
.
const tryPromise: <string, WeatherError>(options: { readonly try: (signal: AbortSignal) => PromiseLike<string>; readonly catch: (error: unknown) => WeatherError; }) => Micro.Micro<...>

Wrap a `Promise` into a `Micro` effect. Any errors will be caught and converted into a specific error type.

tryPromise
({
22
(property) try: (signal: AbortSignal) => PromiseLike<string>
try
: () =>
function fetchWeather(city: string): Promise<string>
fetchWeather
(
(parameter) city: string
city
),
23
// remap the error
24
(property) catch: (error: unknown) => WeatherError
catch
: (
(parameter) error: unknown
error
) => new
constructor WeatherError(message: string): WeatherError
WeatherError
(
var String: StringConstructor (value?: any) => string

Allows manipulation and formatting of text strings and determination and location of substrings within strings.

String
(
(parameter) error: unknown
error
))
25
})
26
}
27
28
const
const weatherEffect: Micro.Micro<string, WeatherError, never>
weatherEffect
=
function getWeather(city: string): Micro.Micro<string, WeatherError, never>
getWeather
("Paris")
29
30
import Micro
Micro
.
const runPromise: <string, WeatherError>(effect: Micro.Micro<string, WeatherError, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const weatherEffect: Micro.Micro<string, WeatherError, never>
weatherEffect
)
31
.
(method) Promise<string>.then<void, never>(onfulfilled?: ((value: string) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
((
(parameter) result: string
result
) =>
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
(`The weather in London is: ${
(parameter) result: string
result
}`))
32
.
(method) Promise<void>.catch<void>(onrejected?: ((reason: any) => void | PromiseLike<void>) | null | undefined): Promise<void>

Attaches a callback for only the rejection of the Promise.

catch
((
(parameter) error: any
error
) =>
33
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.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` 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 code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
(`Failed to fetch weather data: ${
(parameter) error: any
error
}`)
34
)
35
/*
36
Output:
37
Failed to fetch weather data: MicroCause.Fail: {"_tag":"WeatherError","message":"Error: Weather data not found for this location"}
38
*/

These errors, also referred to as failures, typed errors or recoverable errors, are errors that developers anticipate as part of the normal program execution. They serve a similar purpose to checked exceptions and play a role in defining the program’s domain and control flow.

Expected errors are tracked at the type level by the Micro data type in the “Error” channel.

The Micro.either function transforms an Micro<A, E, R> into an effect that encapsulates both potential failure and success within an Either data type.

The resulting effect cannot fail because the potential failure is now represented within the Either’s Left type. The error type of the returned Micro is specified as never, confirming that the effect is structured to not fail.

By yielding an Either, we gain the ability to “pattern match” on this type to handle both failure and success cases within the generator function:

1
import * as
import Either
Either
from "effect/Either"
2
import * as
import Micro
Micro
from "effect/Micro"
3
4
class
class NetworkError
NetworkError
{
5
readonly
(property) NetworkError._tag: "NetworkError"
_tag
= "NetworkError"
6
}
7
8
class
class ValidationError
ValidationError
{
9
readonly
(property) ValidationError._tag: "ValidationError"
_tag
= "ValidationError"
10
}
11
12
const
const task: Micro.Micro<string, NetworkError | ValidationError, never>
task
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<never, NetworkError, never>> | YieldWrap<Micro.Micro<never, ValidationError, never>>, string>(...args: [self: ...] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
13
// Simulate network and validation errors
14
if (
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
(method) Math.random(): number

Returns a pseudorandom number between 0 and 1.

random
() > 0.5) yield*
import Micro
Micro
.
const fail: <NetworkError>(e: NetworkError) => Micro.Micro<never, NetworkError, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(new
constructor NetworkError(): NetworkError
NetworkError
())
15
if (
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
(method) Math.random(): number

Returns a pseudorandom number between 0 and 1.

random
() > 0.5) yield*
import Micro
Micro
.
const fail: <ValidationError>(e: ValidationError) => Micro.Micro<never, ValidationError, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(new
constructor ValidationError(): ValidationError
ValidationError
())
16
return "Success"
17
})
18
19
const
const recovered: Micro.Micro<string, never, never>
recovered
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<Either.Either<string, NetworkError | ValidationError>, never, never>>, string>(...args: [self: unknown, body: (this: unknown) => Generator<...>] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
20
const
const failureOrSuccess: Either.Either<string, NetworkError | ValidationError>
failureOrSuccess
= yield*
import Micro
Micro
.
const either: <string, NetworkError | ValidationError, never>(self: Micro.Micro<string, NetworkError | ValidationError, never>) => Micro.Micro<...>

Replace the success value of the given `Micro` effect with an `Either`, wrapping the success value in `Right` and wrapping any expected errors with a `Left`.

either
(
const task: Micro.Micro<string, NetworkError | ValidationError, never>
task
)
21
return
import Either
Either
.
const match: <string, NetworkError | ValidationError, string, string>(self: Either.Either<string, NetworkError | ValidationError>, options: { ...; }) => string (+1 overload)

Takes two functions and an `Either` value, if the value is a `Left` the inner value is applied to the `onLeft function, if the value is a `Right` the inner value is applied to the `onRight` function.

match
(
const failureOrSuccess: Either.Either<string, NetworkError | ValidationError>
failureOrSuccess
, {
22
(property) onLeft: (left: NetworkError | ValidationError) => string
onLeft
: (
(parameter) error: NetworkError | ValidationError
error
) => `Recovering from ${
(parameter) error: NetworkError | ValidationError
error
.
(property) _tag: "NetworkError" | "ValidationError"
_tag
}`,
23
(property) onRight: (right: string) => string
onRight
: (
(parameter) value: string
value
) => `Result is: ${
(parameter) value: string
value
}`
24
})
25
})
26
27
import Micro
Micro
.
const runPromiseExit: <string, never>(effect: Micro.Micro<string, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const recovered: Micro.Micro<string, never, never>
recovered
).
(method) Promise<MicroExit<string, never>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<string, never>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
28
/*
29
Example Output:
30
{
31
_id: 'Either',
32
_tag: 'Right',
33
right: 'Recovering from ValidationError'
34
}
35
*/

The Micro.catchAll function allows you to catch any error that occurs in the program and provide a fallback.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
class
class NetworkError
NetworkError
{
4
readonly
(property) NetworkError._tag: "NetworkError"
_tag
= "NetworkError"
5
}
6
7
class
class ValidationError
ValidationError
{
8
readonly
(property) ValidationError._tag: "ValidationError"
_tag
= "ValidationError"
9
}
10
11
const
const task: Micro.Micro<string, NetworkError | ValidationError, never>
task
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<never, NetworkError, never>> | YieldWrap<Micro.Micro<never, ValidationError, never>>, string>(...args: [self: ...] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
12
// Simulate network and validation errors
13
if (
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
(method) Math.random(): number

Returns a pseudorandom number between 0 and 1.

random
() > 0.5) yield*
import Micro
Micro
.
const fail: <NetworkError>(e: NetworkError) => Micro.Micro<never, NetworkError, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(new
constructor NetworkError(): NetworkError
NetworkError
())
14
if (
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
(method) Math.random(): number

Returns a pseudorandom number between 0 and 1.

random
() > 0.5) yield*
import Micro
Micro
.
const fail: <ValidationError>(e: ValidationError) => Micro.Micro<never, ValidationError, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(new
constructor ValidationError(): ValidationError
ValidationError
())
15
return "Success"
16
})
17
18
const
const recovered: Micro.Micro<string, never, never>
recovered
=
const task: Micro.Micro<string, NetworkError | ValidationError, never>
task
.
(method) Pipeable.pipe<Micro.Micro<string, NetworkError | ValidationError, never>, Micro.Micro<string, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<string, NetworkError | ValidationError, never>) => Micro.Micro<...>): Micro.Micro<...> (+21 overloads)
pipe
(
19
import Micro
Micro
.
const catchAll: <NetworkError | ValidationError, string, never, never>(f: (e: NetworkError | ValidationError) => Micro.Micro<string, never, never>) => <A, R>(self: Micro.Micro<...>) => Micro.Micro<...> (+1 overload)

Catch the error of the given `Micro` effect, allowing you to recover from it. It only catches expected (`MicroCause.Fail`) errors.

catchAll
((
(parameter) error: NetworkError | ValidationError
error
) =>
20
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(`Recovering from ${
(parameter) error: NetworkError | ValidationError
error
.
(property) _tag: "NetworkError" | "ValidationError"
_tag
}`)
21
)
22
)
23
24
import Micro
Micro
.
const runPromiseExit: <string, never>(effect: Micro.Micro<string, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const recovered: Micro.Micro<string, never, never>
recovered
).
(method) Promise<MicroExit<string, never>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<string, never>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
25
/*
26
Example Output:
27
{ _id: 'Either', _tag: 'Right', right: 'Recovering from NetworkError' }
28
*/

If your program’s errors are all tagged with a _tag field that acts as a discriminator (recommended) you can use the Effect.catchTag function to catch and handle specific errors with precision.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
class
class NetworkError
NetworkError
{
4
readonly
(property) NetworkError._tag: "NetworkError"
_tag
= "NetworkError"
5
}
6
7
class
class ValidationError
ValidationError
{
8
readonly
(property) ValidationError._tag: "ValidationError"
_tag
= "ValidationError"
9
}
10
11
const
const task: Micro.Micro<string, NetworkError | ValidationError, never>
task
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<never, NetworkError, never>> | YieldWrap<Micro.Micro<never, ValidationError, never>>, string>(...args: [self: ...] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
12
// Simulate network and validation errors
13
if (
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
(method) Math.random(): number

Returns a pseudorandom number between 0 and 1.

random
() > 0.5) yield*
import Micro
Micro
.
const fail: <NetworkError>(e: NetworkError) => Micro.Micro<never, NetworkError, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(new
constructor NetworkError(): NetworkError
NetworkError
())
14
if (
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
(method) Math.random(): number

Returns a pseudorandom number between 0 and 1.

random
() > 0.5) yield*
import Micro
Micro
.
const fail: <ValidationError>(e: ValidationError) => Micro.Micro<never, ValidationError, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(new
constructor ValidationError(): ValidationError
ValidationError
())
15
return "Success"
16
})
17
18
const
const recovered: Micro.Micro<string, NetworkError, never>
recovered
=
const task: Micro.Micro<string, NetworkError | ValidationError, never>
task
.
(method) Pipeable.pipe<Micro.Micro<string, NetworkError | ValidationError, never>, Micro.Micro<string, NetworkError, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<...>) => Micro.Micro<...>): Micro.Micro<...> (+21 overloads)
pipe
(
19
import Micro
Micro
.
const catchTag: <"ValidationError", NetworkError | ValidationError, string, never, never>(k: "ValidationError", f: (e: ValidationError) => Micro.Micro<string, never, never>) => <A, R>(self: Micro.Micro<...>) => Micro.Micro<...> (+1 overload)

Recovers from the specified tagged error.

catchTag
("ValidationError", (
(parameter) _error: ValidationError
_error
) =>
20
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
("Recovering from ValidationError")
21
)
22
)
23
24
import Micro
Micro
.
const runPromiseExit: <string, NetworkError>(effect: Micro.Micro<string, NetworkError, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const recovered: Micro.Micro<string, NetworkError, never>
recovered
).
(method) Promise<MicroExit<string, NetworkError>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<string, NetworkError>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<...>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
25
/*
26
Example Output:
27
{
28
_id: 'Either',
29
_tag: 'Right',
30
right: 'Recovering from ValidationError'
31
}
32
*/

Unexpected errors, also referred to as defects, untyped errors, or unrecoverable errors, are errors that developers do not anticipate occurring during normal program execution. Unlike expected errors, which are considered part of a program’s domain and control flow, unexpected errors resemble unchecked exceptions and lie outside the expected behavior of the program.

Since these errors are not expected, Effect does not track them at the type level. However, the Effect runtime does keep track of these errors and provides several methods to aid in recovering from unexpected errors.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const divide: (a: number, b: number) => Micro.Micro<number>
divide
= (
(parameter) a: number
a
: number,
(parameter) b: number
b
: number):
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number> =>
4
(parameter) b: number
b
=== 0
5
?
import Micro
Micro
.
const die: (defect: unknown) => Micro.Micro<never>

Creates a `Micro` effect that will die with the specified error. This will result in a `CauseDie`, where the error is not tracked at the type level.

die
(new
var Error: ErrorConstructor new (message?: string) => Error
Error
("Cannot divide by zero"))
6
:
import Micro
Micro
.
const succeed: <number>(a: number) => Micro.Micro<number, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(
(parameter) a: number
a
/
(parameter) b: number
b
)
7
8
import Micro
Micro
.
const runSync: <number, never>(effect: Micro.Micro<number, never, never>) => number

Attempt to execute the `Micro` effect synchronously and return the success value.

runSync
(
const divide: (a: number, b: number) => Micro.Micro<number>
divide
(1, 0)) // throws Error: Cannot divide by zero
1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const divide: (a: number, b: number) => Micro.Micro<number, Error>
divide
= (
(parameter) a: number
a
: number,
(parameter) b: number
b
: number):
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number,
interface Error
Error
> =>
4
(parameter) b: number
b
=== 0
5
?
import Micro
Micro
.
const fail: <Error>(e: Error) => Micro.Micro<never, Error, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(new
var Error: ErrorConstructor new (message?: string) => Error
Error
("Cannot divide by zero"))
6
:
import Micro
Micro
.
const succeed: <number>(a: number) => Micro.Micro<number, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(
(parameter) a: number
a
/
(parameter) b: number
b
)
7
8
const
const program: Micro.Micro<number, never, never>
program
=
import Micro
Micro
.
const orDie: <number, Error, never>(self: Micro.Micro<number, Error, never>) => Micro.Micro<number, never, never>

Elevate any expected errors of the given `Micro` effect to unexpected errors, resulting in an error type of `never`.

orDie
(
const divide: (a: number, b: number) => Micro.Micro<number, Error>
divide
(1, 0))
9
10
import Micro
Micro
.
const runSync: <number, never>(effect: Micro.Micro<number, never, never>) => number

Attempt to execute the `Micro` effect synchronously and return the success value.

runSync
(
const program: Micro.Micro<number, never, never>
program
) // throws Error: Cannot divide by zero
1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
= (
(parameter) message: string
message
: string) =>
4
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
(
(parameter) message: string
message
))
5
6
const
const program: Micro.Micro<void, never, never>
program
=
import Micro
Micro
.
const catchAllDefect: <never, never, never, void, never, never>(self: Micro.Micro<never, never, never>, f: (defect: unknown) => Micro.Micro<void, never, never>) => Micro.Micro<void, never, never> (+1 overload)

Catch any unexpected errors of the given `Micro` effect, allowing you to recover from them.

catchAllDefect
(
7
import Micro
Micro
.
const die: (defect: unknown) => Micro.Micro<never>

Creates a `Micro` effect that will die with the specified error. This will result in a `CauseDie`, where the error is not tracked at the type level.

die
("Boom!"), // Simulating a runtime error
8
(
(parameter) defect: unknown
defect
) =>
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`Unknown defect caught: ${
(parameter) defect: unknown
defect
}`)
9
)
10
11
// We get an Either.Right because we caught all defects
12
import Micro
Micro
.
const runPromiseExit: <void, never>(effect: Micro.Micro<void, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const program: Micro.Micro<void, never, never>
program
).
(method) Promise<MicroExit<void, never>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<void, never>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
13
/*
14
Output:
15
Unknown defect caught: Boom!
16
{ _id: 'Either', _tag: 'Right', right: undefined }
17
*/

The Micro.orElseSucceed function will always replace the original failure with a success value, so the resulting effect cannot fail:

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
class
class NegativeAgeError
NegativeAgeError
{
4
readonly
(property) NegativeAgeError._tag: "NegativeAgeError"
_tag
= "NegativeAgeError"
5
constructor(readonly
(property) NegativeAgeError.age: number
age
: number) {}
6
}
7
8
class
class IllegalAgeError
IllegalAgeError
{
9
readonly
(property) IllegalAgeError._tag: "IllegalAgeError"
_tag
= "IllegalAgeError"
10
constructor(readonly
(property) IllegalAgeError.age: number
age
: number) {}
11
}
12
13
const
const validate: (age: number) => Micro.Micro<number, NegativeAgeError | IllegalAgeError>
validate
= (
14
(parameter) age: number
age
: number
15
):
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number,
class NegativeAgeError
NegativeAgeError
|
class IllegalAgeError
IllegalAgeError
> => {
16
if (
(parameter) age: number
age
< 0) {
17
return
import Micro
Micro
.
const fail: <NegativeAgeError>(e: NegativeAgeError) => Micro.Micro<never, NegativeAgeError, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(new
constructor NegativeAgeError(age: number): NegativeAgeError
NegativeAgeError
(
(parameter) age: number
age
))
18
} else if (
(parameter) age: number
age
< 18) {
19
return
import Micro
Micro
.
const fail: <IllegalAgeError>(e: IllegalAgeError) => Micro.Micro<never, IllegalAgeError, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(new
constructor IllegalAgeError(age: number): IllegalAgeError
IllegalAgeError
(
(parameter) age: number
age
))
20
} else {
21
return
import Micro
Micro
.
const succeed: <number>(a: number) => Micro.Micro<number, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(
(parameter) age: number
age
)
22
}
23
}
24
25
const
const program: Micro.Micro<number, never, never>
program
=
import Micro
Micro
.
const orElseSucceed: <number, NegativeAgeError | IllegalAgeError, never, number>(self: Micro.Micro<number, NegativeAgeError | IllegalAgeError, never>, f: LazyArg<...>) => Micro.Micro<...> (+1 overload)

Recover from all errors by succeeding with the given value.

orElseSucceed
(
const validate: (age: number) => Micro.Micro<number, NegativeAgeError | IllegalAgeError>
validate
(3), () => 0)
1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const success: Micro.Micro<number, Error, never>
success
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number,
interface Error
Error
> =
import Micro
Micro
.
const succeed: <number>(a: number) => Micro.Micro<number, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(42)
4
const
const failure: Micro.Micro<number, Error, never>
failure
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number,
interface Error
Error
> =
import Micro
Micro
.
const fail: <Error>(e: Error) => Micro.Micro<never, Error, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(
5
new
var Error: ErrorConstructor new (message?: string) => Error
Error
("Uh oh!")
6
)
7
8
const
const program1: Micro.Micro<string, never, never>
program1
=
import Micro
Micro
.
const match: <number, Error, never, string, string>(self: Micro.Micro<number, Error, never>, options: { readonly onFailure: (error: Error) => string; readonly onSuccess: (value: number) => string; }) => Micro.Micro<...> (+1 overload)
match
(
const success: Micro.Micro<number, Error, never>
success
, {
9
(property) onFailure: (error: Error) => string
onFailure
: (
(parameter) error: Error
error
) => `failure: ${
(parameter) error: Error
error
.
(property) Error.message: string
message
}`,
10
(property) onSuccess: (value: number) => string
onSuccess
: (
(parameter) value: number
value
) => `success: ${
(parameter) value: number
value
}`
11
})
12
13
import Micro
Micro
.
const runPromise: <string, never>(effect: Micro.Micro<string, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program1: Micro.Micro<string, never, never>
program1
).
(method) Promise<string>.then<void, never>(onfulfilled?: ((value: string) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
) // Output: "success: 42"
14
15
const
const program2: Micro.Micro<string, never, never>
program2
=
import Micro
Micro
.
const match: <number, Error, never, string, string>(self: Micro.Micro<number, Error, never>, options: { readonly onFailure: (error: Error) => string; readonly onSuccess: (value: number) => string; }) => Micro.Micro<...> (+1 overload)
match
(
const failure: Micro.Micro<number, Error, never>
failure
, {
16
(property) onFailure: (error: Error) => string
onFailure
: (
(parameter) error: Error
error
) => `failure: ${
(parameter) error: Error
error
.
(property) Error.message: string
message
}`,
17
(property) onSuccess: (value: number) => string
onSuccess
: (
(parameter) value: number
value
) => `success: ${
(parameter) value: number
value
}`
18
})
19
20
import Micro
Micro
.
const runPromise: <string, never>(effect: Micro.Micro<string, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program2: Micro.Micro<string, never, never>
program2
).
(method) Promise<string>.then<void, never>(onfulfilled?: ((value: string) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
) // Output: "failure: Uh oh!"
1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
= (
(parameter) message: string
message
: string) =>
4
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
(
(parameter) message: string
message
))
5
6
const
const success: Micro.Micro<number, Error, never>
success
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number,
interface Error
Error
> =
import Micro
Micro
.
const succeed: <number>(a: number) => Micro.Micro<number, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(42)
7
const
const failure: Micro.Micro<number, Error, never>
failure
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number,
interface Error
Error
> =
import Micro
Micro
.
const fail: <Error>(e: Error) => Micro.Micro<never, Error, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(
8
new
var Error: ErrorConstructor new (message?: string) => Error
Error
("Uh oh!")
9
)
10
11
const
const program1: Micro.Micro<string, never, never>
program1
=
import Micro
Micro
.
const matchEffect: <number, Error, never, string, never, never, string, never, never>(self: Micro.Micro<number, Error, never>, options: { readonly onFailure: (e: Error) => Micro.Micro<string, never, never>; readonly onSuccess: (a: number) => Micro.Micro<...>; }) => Micro.Micro<...> (+1 overload)
matchEffect
(
const success: Micro.Micro<number, Error, never>
success
, {
12
(property) onFailure: (e: Error) => Micro.Micro<string, never, never>
onFailure
: (
(parameter) error: Error
error
) =>
13
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(`failure: ${
(parameter) error: Error
error
.
(property) Error.message: string
message
}`).
(method) Pipeable.pipe<Micro.Micro<string, never, never>, Micro.Micro<string, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<string, never, never>) => Micro.Micro<string, never, never>): Micro.Micro<...> (+21 overloads)
pipe
(
14
import Micro
Micro
.
const tap: <string, Micro.Micro<void, never, never>>(f: (a: string) => Micro.Micro<void, never, never>) => <E, R>(self: Micro.Micro<string, E, R>) => Micro.Micro<string, E, R> (+3 overloads)

Execute a side effect from the success value of the `Micro` effect. It is similar to the `andThen` api, but the success value is ignored.

tap
(
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
)
15
),
16
(property) onSuccess: (a: number) => Micro.Micro<string, never, never>
onSuccess
: (
(parameter) value: number
value
) =>
17
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(`success: ${
(parameter) value: number
value
}`).
(method) Pipeable.pipe<Micro.Micro<string, never, never>, Micro.Micro<string, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<string, never, never>) => Micro.Micro<string, never, never>): Micro.Micro<...> (+21 overloads)
pipe
(
import Micro
Micro
.
const tap: <string, Micro.Micro<void, never, never>>(f: (a: string) => Micro.Micro<void, never, never>) => <E, R>(self: Micro.Micro<string, E, R>) => Micro.Micro<string, E, R> (+3 overloads)

Execute a side effect from the success value of the `Micro` effect. It is similar to the `andThen` api, but the success value is ignored.

tap
(
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
))
18
})
19
20
import Micro
Micro
.
const runSync: <string, never>(effect: Micro.Micro<string, never, never>) => string

Attempt to execute the `Micro` effect synchronously and return the success value.

runSync
(
const program1: Micro.Micro<string, never, never>
program1
)
21
/*
22
Output:
23
success: 42
24
*/
25
26
const
const program2: Micro.Micro<string, never, never>
program2
=
import Micro
Micro
.
const matchEffect: <number, Error, never, string, never, never, string, never, never>(self: Micro.Micro<number, Error, never>, options: { readonly onFailure: (e: Error) => Micro.Micro<string, never, never>; readonly onSuccess: (a: number) => Micro.Micro<...>; }) => Micro.Micro<...> (+1 overload)
matchEffect
(
const failure: Micro.Micro<number, Error, never>
failure
, {
27
(property) onFailure: (e: Error) => Micro.Micro<string, never, never>
onFailure
: (
(parameter) error: Error
error
) =>
28
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(`failure: ${
(parameter) error: Error
error
.
(property) Error.message: string
message
}`).
(method) Pipeable.pipe<Micro.Micro<string, never, never>, Micro.Micro<string, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<string, never, never>) => Micro.Micro<string, never, never>): Micro.Micro<...> (+21 overloads)
pipe
(
29
import Micro
Micro
.
const tap: <string, Micro.Micro<void, never, never>>(f: (a: string) => Micro.Micro<void, never, never>) => <E, R>(self: Micro.Micro<string, E, R>) => Micro.Micro<string, E, R> (+3 overloads)

Execute a side effect from the success value of the `Micro` effect. It is similar to the `andThen` api, but the success value is ignored.

tap
(
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
)
30
),
31
(property) onSuccess: (a: number) => Micro.Micro<string, never, never>
onSuccess
: (
(parameter) value: number
value
) =>
32
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(`success: ${
(parameter) value: number
value
}`).
(method) Pipeable.pipe<Micro.Micro<string, never, never>, Micro.Micro<string, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<string, never, never>) => Micro.Micro<string, never, never>): Micro.Micro<...> (+21 overloads)
pipe
(
import Micro
Micro
.
const tap: <string, Micro.Micro<void, never, never>>(f: (a: string) => Micro.Micro<void, never, never>) => <E, R>(self: Micro.Micro<string, E, R>) => Micro.Micro<string, E, R> (+3 overloads)

Execute a side effect from the success value of the `Micro` effect. It is similar to the `andThen` api, but the success value is ignored.

tap
(
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
))
33
})
34
35
import Micro
Micro
.
const runSync: <string, never>(effect: Micro.Micro<string, never, never>) => string

Attempt to execute the `Micro` effect synchronously and return the success value.

runSync
(
const program2: Micro.Micro<string, never, never>
program2
)
36
/*
37
Output:
38
failure: Uh oh!
39
*/
1
import * as
import Micro
Micro
from "effect/Micro"
2
3
declare const
const exceptionalEffect: Micro.Micro<void, Error, never>
exceptionalEffect
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<void,
interface Error
Error
>
4
5
const
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
= (
(parameter) message: string
message
: string) =>
6
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
(
(parameter) message: string
message
))
7
8
const
const program: Micro.Micro<void, never, never>
program
=
import Micro
Micro
.
const matchCauseEffect: <void, Error, never, void, never, never, void, never, never>(self: Micro.Micro<void, Error, never>, options: { readonly onFailure: (cause: Micro.MicroCause<Error>) => Micro.Micro<...>; readonly onSuccess: (a: void) => Micro.Micro<...>; }) => Micro.Micro<...> (+1 overload)
matchCauseEffect
(
const exceptionalEffect: Micro.Micro<void, Error, never>
exceptionalEffect
, {
9
(property) onFailure: (cause: Micro.MicroCause<Error>) => Micro.Micro<void, never, never>
onFailure
: (
(parameter) cause: Micro.MicroCause<Error>
cause
) => {
10
switch (
(parameter) cause: Micro.MicroCause<Error>
cause
.
(property) MicroCause<E>.Proto<Tag extends string, E>._tag: "Die" | "Interrupt" | "Fail"
_tag
) {
11
case "Fail":
12
return
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`Fail: ${
(parameter) cause: Micro.MicroCause.Fail<Error>
cause
.
(property) MicroCause<E>.Fail<Error>.error: Error
error
.
(property) Error.message: string
message
}`)
13
case "Die":
14
return
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`Die: ${
(parameter) cause: Micro.MicroCause.Die
cause
.
(property) MicroCause<E>.Die.defect: unknown
defect
}`)
15
case "Interrupt":
16
return
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
("interrupted!")
17
}
18
},
19
(property) onSuccess: (a: void) => Micro.Micro<void, never, never>
onSuccess
: (
(parameter) value: void
value
) =>
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`succeeded with ${
(parameter) value: void
value
} value`)
20
})

To demonstrate the functionality of the Micro.retry function, we will be working with the following helper that simulates an effect with possible failures:

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
let
let count: number
count
= 0
4
5
// Simulates an effect with possible failures
6
const
const effect: Micro.Micro<string, Error, never>
effect
=
import Micro
Micro
.
const async: <string, Error, never>(register: (resume: (effect: Micro.Micro<string, Error, never>) => void, signal: AbortSignal) => void | Micro.Micro<void, never, never>) => Micro.Micro<...>

Create a `Micro` effect from an asynchronous computation. You can return a cleanup effect that will be run when the effect is aborted. It is also passed an `AbortSignal` that is triggered when the effect is aborted.

async
<string,
interface Error
Error
>((
(parameter) resume: (effect: Micro.Micro<string, Error, never>) => void
resume
) => {
7
if (
let count: number
count
<= 2) {
8
let count: number
count
++
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
("failure")
10
(parameter) resume: (effect: Micro.Micro<string, Error, never>) => void
resume
(
import Micro
Micro
.
const fail: <Error>(e: Error) => Micro.Micro<never, Error, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(new
var Error: ErrorConstructor new (message?: string) => Error
Error
()))
11
} else {
12
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
("success")
13
(parameter) resume: (effect: Micro.Micro<string, Error, never>) => void
resume
(
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
("yay!"))
14
}
15
})
1
import * as
import Micro
Micro
from "effect/Micro"
2
3
let
let count: number
count
= 0
4
5
// Simulates an effect with possible failures
6
const
const effect: Micro.Micro<string, Error, never>
effect
=
import Micro
Micro
.
const async: <string, Error, never>(register: (resume: (effect: Micro.Micro<string, Error, never>) => void, signal: AbortSignal) => void | Micro.Micro<void, never, never>) => Micro.Micro<...>

Create a `Micro` effect from an asynchronous computation. You can return a cleanup effect that will be run when the effect is aborted. It is also passed an `AbortSignal` that is triggered when the effect is aborted.

async
<string,
interface Error
Error
>((
(parameter) resume: (effect: Micro.Micro<string, Error, never>) => void
resume
) => {
7
if (
let count: number
count
<= 2) {
8
let count: number
count
++
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
("failure")
10
(parameter) resume: (effect: Micro.Micro<string, Error, never>) => void
resume
(
import Micro
Micro
.
const fail: <Error>(e: Error) => Micro.Micro<never, Error, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
(new
var Error: ErrorConstructor new (message?: string) => Error
Error
()))
11
} else {
12
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
("success")
13
(parameter) resume: (effect: Micro.Micro<string, Error, never>) => void
resume
(
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
("yay!"))
14
}
15
})
16
17
// Define a repetition policy using a spaced delay between retries
18
const
const policy: Micro.MicroSchedule
policy
=
import Micro
Micro
.
const scheduleSpaced: (millis: number) => Micro.MicroSchedule

Create a `MicroSchedule` that will generate a constant delay.

scheduleSpaced
(100)
19
20
const
const repeated: Micro.Micro<string, Error, never>
repeated
=
import Micro
Micro
.
const retry: <string, Error, never>(self: Micro.Micro<string, Error, never>, options?: { while?: Predicate<Error> | undefined; times?: number | undefined; schedule?: Micro.MicroSchedule | undefined; } | undefined) => Micro.Micro<...> (+1 overload)

Retry the given `Micro` effect using the provided options.

retry
(
const effect: Micro.Micro<string, Error, never>
effect
, {
(property) schedule?: Micro.MicroSchedule | undefined
schedule
:
const policy: Micro.MicroSchedule
policy
})
21
22
import Micro
Micro
.
const runPromise: <string, Error>(effect: Micro.Micro<string, Error, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const repeated: Micro.Micro<string, Error, never>
repeated
).
(method) Promise<string>.then<void, never>(onfulfilled?: ((value: string) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
23
/*
24
Output:
25
failure
26
failure
27
failure
28
success
29
yay!
30
*/

The Micro.sandbox function allows you to encapsulate all the potential causes of an error in an effect. It exposes the full MicroCause of an effect, whether it’s due to a failure, fiber interruption, or defect.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
= (
(parameter) message: string
message
: string) =>
4
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
(
(parameter) message: string
message
))
5
6
const
const effect: Micro.Micro<string, string, never>
effect
=
import Micro
Micro
.
const fail: <string>(e: string) => Micro.Micro<never, string, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
("Oh uh!").
(method) Pipeable.pipe<Micro.Micro<never, string, never>, Micro.Micro<string, string, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<never, string, never>) => Micro.Micro<string, string, never>): Micro.Micro<...> (+21 overloads)
pipe
(
import Micro
Micro
.
const as: <never, string>(value: string) => <E, R>(self: Micro.Micro<never, E, R>) => Micro.Micro<string, E, R> (+1 overload)

Create a `Micro` effect that will replace the success value of the given effect.

as
("primary result"))
7
8
const
const sandboxed: Micro.Micro<string, Micro.MicroCause<string>, never>
sandboxed
=
import Micro
Micro
.
const sandbox: <string, string, never>(self: Micro.Micro<string, string, never>) => Micro.Micro<string, Micro.MicroCause<string>, never>

Replace the error type of the given `Micro` with the full `MicroCause` object.

sandbox
(
const effect: Micro.Micro<string, string, never>
effect
)
9
10
const
const program: Micro.Micro<string, never, never>
program
=
const sandboxed: Micro.Micro<string, Micro.MicroCause<string>, never>
sandboxed
.
(method) Pipeable.pipe<Micro.Micro<string, Micro.MicroCause<string>, never>, Micro.Micro<string, Micro.MicroCause<E>.Die | Micro.MicroCause.Interrupt, never>, Micro.Micro<...>, Micro.Micro<...>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<...>) => Micro.Micro<...>, bc: (_: Micro.Micro<...>) => Micro.Micro<...>, cd: (_: Micro.Micro<...>) => Micro.Micro<...>): Micro.Micro<...> (+21 overloads)
pipe
(
11
import Micro
Micro
.
const catchTag: <"Fail", Micro.MicroCause<string>, string, never, never>(k: "Fail", f: (e: Micro.MicroCause<E>.Fail<string>) => Micro.Micro<string, never, never>) => <A, R>(self: Micro.Micro<...>) => Micro.Micro<...> (+1 overload)

Recovers from the specified tagged error.

catchTag
("Fail", (
(parameter) cause: Micro.MicroCause.Fail<string>
cause
) =>
12
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`Caught a defect: ${
(parameter) cause: Micro.MicroCause.Fail<string>
cause
.
(property) MicroCause<E>.Fail<string>.error: string
error
}`).
(method) Pipeable.pipe<Micro.Micro<void, never, never>, Micro.Micro<string, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<void, never, never>) => Micro.Micro<string, never, never>): Micro.Micro<...> (+21 overloads)
pipe
(
13
import Micro
Micro
.
const as: <void, string>(value: string) => <E, R>(self: Micro.Micro<void, E, R>) => Micro.Micro<string, E, R> (+1 overload)

Create a `Micro` effect that will replace the success value of the given effect.

as
("fallback result on expected error")
14
)
15
),
16
import Micro
Micro
.
const catchTag: <"Interrupt", Micro.MicroCause<E>.Die | Micro.MicroCause.Interrupt, string, never, never>(k: "Interrupt", f: (e: Micro.MicroCause.Interrupt) => Micro.Micro<string, never, never>) => <A, R>(self: Micro.Micro<...>) => Micro.Micro<...> (+1 overload)

Recovers from the specified tagged error.

catchTag
("Interrupt", () =>
17
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`Caught a defect`).
(method) Pipeable.pipe<Micro.Micro<void, never, never>, Micro.Micro<string, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<void, never, never>) => Micro.Micro<string, never, never>): Micro.Micro<...> (+21 overloads)
pipe
(
18
import Micro
Micro
.
const as: <void, string>(value: string) => <E, R>(self: Micro.Micro<void, E, R>) => Micro.Micro<string, E, R> (+1 overload)

Create a `Micro` effect that will replace the success value of the given effect.

as
("fallback result on fiber interruption")
19
)
20
),
21
import Micro
Micro
.
const catchTag: <"Die", Micro.MicroCause<E>.Die, string, never, never>(k: "Die", f: (e: Micro.MicroCause.Die) => Micro.Micro<string, never, never>) => <A, R>(self: Micro.Micro<A, Micro.MicroCause.Die, R>) => Micro.Micro<...> (+1 overload)

Recovers from the specified tagged error.

catchTag
("Die", (
(parameter) cause: Micro.MicroCause.Die
cause
) =>
22
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`Caught a defect: ${
(parameter) cause: Micro.MicroCause.Die
cause
.
(property) MicroCause<E>.Die.defect: unknown
defect
}`).
(method) Pipeable.pipe<Micro.Micro<void, never, never>, Micro.Micro<string, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<void, never, never>) => Micro.Micro<string, never, never>): Micro.Micro<...> (+21 overloads)
pipe
(
23
import Micro
Micro
.
const as: <void, string>(value: string) => <E, R>(self: Micro.Micro<void, E, R>) => Micro.Micro<string, E, R> (+1 overload)

Create a `Micro` effect that will replace the success value of the given effect.

as
("fallback result on unexpected error")
24
)
25
)
26
)
27
28
import Micro
Micro
.
const runPromise: <string, never>(effect: Micro.Micro<string, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program: Micro.Micro<string, never, never>
program
).
(method) Promise<string>.then<void, never>(onfulfilled?: ((value: string) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
29
/*
30
Output:
31
Caught a defect: Oh uh!
32
fallback result on expected error
33
*/

Executes an effectful operation to inspect the failure of an effect without altering it.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
= (
(parameter) message: string
message
: string) =>
4
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
(
(parameter) message: string
message
))
5
6
// Create an effect that is designed to fail, simulating an occurrence of a network error
7
const
const task: Micro.Micro<number, string, never>
task
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number, string> =
import Micro
Micro
.
const fail: <string>(e: string) => Micro.Micro<never, string, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
("NetworkError")
8
9
// Log the error message if the task fails. This function only executes if there is an error,
10
// providing a method to handle or inspect errors without altering the outcome of the original effect.
11
const
const tapping: Micro.Micro<number, string, never>
tapping
=
import Micro
Micro
.
const tapError: <number, string, never, void, never, never>(self: Micro.Micro<number, string, never>, f: (e: string) => Micro.Micro<void, never, never>) => Micro.Micro<number, string, never> (+1 overload)

Perform a side effect from expected errors of the given `Micro`.

tapError
(
const task: Micro.Micro<number, string, never>
task
, (
(parameter) error: string
error
) =>
12
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`expected error: ${
(parameter) error: string
error
}`)
13
)
14
15
import Micro
Micro
.
const runFork: <number, string>(effect: Micro.Micro<number, string, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Micro.Handle<...>

Execute the `Micro` effect and return a `Handle` that can be awaited, joined, or aborted. You can listen for the result by adding an observer using the handle's `addObserver` method.

runFork
(
const tapping: Micro.Micro<number, string, never>
tapping
)
16
/*
17
Output:
18
expected error: NetworkError
19
*/

Inspects the underlying cause of an effect’s failure.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
= (
(parameter) message: string
message
: string) =>
4
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
(
(parameter) message: string
message
))
5
6
// Create an effect that is designed to fail, simulating an occurrence of a network error
7
const
const task1: Micro.Micro<number, string, never>
task1
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number, string> =
import Micro
Micro
.
const fail: <string>(e: string) => Micro.Micro<never, string, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
("NetworkError")
8
// This will log the cause of any expected error or defect
9
const
const tapping1: Micro.Micro<number, string, never>
tapping1
=
import Micro
Micro
.
const tapErrorCause: <number, string, never, void, never, never>(self: Micro.Micro<number, string, never>, f: (cause: Micro.MicroCause<string>) => Micro.Micro<void, never, never>) => Micro.Micro<...> (+1 overload)

Perform a side effect using the full `MicroCause` object of the given `Micro`.

tapErrorCause
(
const task1: Micro.Micro<number, string, never>
task1
, (
(parameter) cause: Micro.MicroCause<string>
cause
) =>
10
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`error cause: ${
(parameter) cause: Micro.MicroCause<string>
cause
}`)
11
)
12
13
import Micro
Micro
.
const runFork: <number, string>(effect: Micro.Micro<number, string, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Micro.Handle<...>

Execute the `Micro` effect and return a `Handle` that can be awaited, joined, or aborted. You can listen for the result by adding an observer using the handle's `addObserver` method.

runFork
(
const tapping1: Micro.Micro<number, string, never>
tapping1
)
14
/*
15
Output:
16
error cause: MicroCause.Fail: NetworkError
17
*/
18
19
// Simulate a severe failure in the system by causing a defect with a specific message.
20
const
const task2: Micro.Micro<number, string, never>
task2
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number, string> =
import Micro
Micro
.
const die: (defect: unknown) => Micro.Micro<never>

Creates a `Micro` effect that will die with the specified error. This will result in a `CauseDie`, where the error is not tracked at the type level.

die
(
21
"Something went wrong"
22
)
23
24
// This will log the cause of any expected error or defect
25
const
const tapping2: Micro.Micro<number, string, never>
tapping2
=
import Micro
Micro
.
const tapErrorCause: <number, string, never, void, never, never>(self: Micro.Micro<number, string, never>, f: (cause: Micro.MicroCause<string>) => Micro.Micro<void, never, never>) => Micro.Micro<...> (+1 overload)

Perform a side effect using the full `MicroCause` object of the given `Micro`.

tapErrorCause
(
const task2: Micro.Micro<number, string, never>
task2
, (
(parameter) cause: Micro.MicroCause<string>
cause
) =>
26
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`error cause: ${
(parameter) cause: Micro.MicroCause<string>
cause
}`)
27
)
28
29
import Micro
Micro
.
const runFork: <number, string>(effect: Micro.Micro<number, string, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Micro.Handle<...>

Execute the `Micro` effect and return a `Handle` that can be awaited, joined, or aborted. You can listen for the result by adding an observer using the handle's `addObserver` method.

runFork
(
const tapping2: Micro.Micro<number, string, never>
tapping2
)
30
/*
31
Output:
32
error cause: MicroCause.Die: Something went wrong
33
*/

Specifically inspects non-recoverable failures or defects in an effect.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
= (
(parameter) message: string
message
: string) =>
4
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
(
(parameter) message: string
message
))
5
6
// Create an effect that is designed to fail, simulating an occurrence of a network error
7
const
const task1: Micro.Micro<number, string, never>
task1
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number, string> =
import Micro
Micro
.
const fail: <string>(e: string) => Micro.Micro<never, string, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
("NetworkError")
8
9
// this won't log anything because is not a defect
10
const
const tapping1: Micro.Micro<number, string, never>
tapping1
=
import Micro
Micro
.
const tapDefect: <number, string, never, void, never, never>(self: Micro.Micro<number, string, never>, f: (defect: unknown) => Micro.Micro<void, never, never>) => Micro.Micro<number, string, never> (+1 overload)

Perform a side effect from unexpected errors of the given `Micro`.

tapDefect
(
const task1: Micro.Micro<number, string, never>
task1
, (
(parameter) cause: unknown
cause
) =>
11
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`defect: ${
(parameter) cause: unknown
cause
}`)
12
)
13
14
import Micro
Micro
.
const runFork: <number, string>(effect: Micro.Micro<number, string, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Micro.Handle<...>

Execute the `Micro` effect and return a `Handle` that can be awaited, joined, or aborted. You can listen for the result by adding an observer using the handle's `addObserver` method.

runFork
(
const tapping1: Micro.Micro<number, string, never>
tapping1
)
15
/*
16
No Output
17
*/
18
19
// Simulate a severe failure in the system by causing a defect with a specific message.
20
const
const task2: Micro.Micro<number, string, never>
task2
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number, string> =
import Micro
Micro
.
const die: (defect: unknown) => Micro.Micro<never>

Creates a `Micro` effect that will die with the specified error. This will result in a `CauseDie`, where the error is not tracked at the type level.

die
(
21
"Something went wrong"
22
)
23
24
// This will only log defects, not errors
25
const
const tapping2: Micro.Micro<number, string, never>
tapping2
=
import Micro
Micro
.
const tapDefect: <number, string, never, void, never, never>(self: Micro.Micro<number, string, never>, f: (defect: unknown) => Micro.Micro<void, never, never>) => Micro.Micro<number, string, never> (+1 overload)

Perform a side effect from unexpected errors of the given `Micro`.

tapDefect
(
const task2: Micro.Micro<number, string, never>
task2
, (
(parameter) cause: unknown
cause
) =>
26
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`defect: ${
(parameter) cause: unknown
cause
}`)
27
)
28
29
import Micro
Micro
.
const runFork: <number, string>(effect: Micro.Micro<number, string, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Micro.Handle<...>

Execute the `Micro` effect and return a `Handle` that can be awaited, joined, or aborted. You can listen for the result by adding an observer using the handle's `addObserver` method.

runFork
(
const tapping2: Micro.Micro<number, string, never>
tapping2
)
30
/*
31
Output:
32
defect: Something went wrong
33
*/

“Yieldable Errors” are special types of errors that can be yielded within a generator function used by Micro.gen. The unique feature of these errors is that you don’t need to use the Micro.fail API explicitly to handle them. They offer a more intuitive and convenient way to work with custom errors in your code.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
class
class MyError
MyError
extends
import Micro
Micro
.
const Error: new <A extends Record<string, any> = {}>(args: Equals<A, {}> extends true ? void : { readonly [P in keyof A]: A[P]; }) => Micro.YieldableError & Readonly<A>
Error
<{
(property) message: string
message
: string }> {}
4
5
export const
const program: Micro.Micro<void, MyError, never>
program
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<never, MyError, never>>, void>(...args: [self: unknown, body: (this: unknown) => Generator<YieldWrap<Micro.Micro<never, MyError, never>>, void, never>] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
6
// same as yield* Effect.fail(new MyError({ message: "Oh no!" })
7
yield* new
constructor MyError<{ message: string; }>(args: { readonly message: string; }): MyError
MyError
({
(property) message: string
message
: "Oh no!" })
8
})
9
10
import Micro
Micro
.
const runPromiseExit: <void, MyError>(effect: Micro.Micro<void, MyError, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const program: Micro.Micro<void, MyError, never>
program
).
(method) Promise<MicroExit<void, MyError>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<void, MyError>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
11
/*
12
Output:
13
{
14
_id: 'Either',
15
_tag: 'Left',
16
left: (MicroCause.Fail) Error: Oh no!
17
...stack trace...
18
}
19
*/
1
import * as
import Micro
Micro
from "effect/Micro"
2
3
// An error with _tag: "Foo"
4
class
class FooError
FooError
extends
import Micro
Micro
.
const TaggedError: <"Foo">(tag: "Foo") => new <A>(args: Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Micro.YieldableError & { ...; } & Readonly<...>
TaggedError
("Foo")<{
5
(property) message: string
message
: string
6
}> {}
7
8
// An error with _tag: "Bar"
9
class
class BarError
BarError
extends
import Micro
Micro
.
const TaggedError: <"Bar">(tag: "Bar") => new <A>(args: Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Micro.YieldableError & { ...; } & Readonly<...>
TaggedError
("Bar")<{
10
(property) randomNumber: number
randomNumber
: number
11
}> {}
12
13
export const
const program: Micro.Micro<string, never, never>
program
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<never, FooError, never>> | YieldWrap<Micro.Micro<never, BarError, never>>, string>(...args: [self: ...] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
14
const
const n: number
n
=
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
(method) Math.random(): number

Returns a pseudorandom number between 0 and 1.

random
()
15
return
const n: number
n
> 0.5
16
? "yay!"
17
:
const n: number
n
< 0.2
18
? yield* new
constructor FooError<{ message: string; }>(args: { readonly message: string; }): FooError
FooError
({
(property) message: string
message
: "Oh no!" })
19
: yield* new
constructor BarError<{ randomNumber: number; }>(args: { readonly randomNumber: number; }): BarError
BarError
({
(property) randomNumber: number
randomNumber
:
const n: number
n
})
20
}).
(method) Pipeable.pipe<Micro.Micro<string, FooError | BarError, never>, Micro.Micro<string, BarError, never>, Micro.Micro<string, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<...>) => Micro.Micro<...>, bc: (_: Micro.Micro<...>) => Micro.Micro<...>): Micro.Micro<...> (+21 overloads)
pipe
(
21
import Micro
Micro
.
const catchTag: <"Foo", FooError | BarError, string, never, never>(k: "Foo", f: (e: FooError) => Micro.Micro<string, never, never>) => <A, R>(self: Micro.Micro<A, FooError | BarError, R>) => Micro.Micro<...> (+1 overload)

Recovers from the specified tagged error.

catchTag
("Foo", (
(parameter) error: FooError
error
) =>
22
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(`Foo error: ${
(parameter) error: FooError
error
.
(property) message: string
message
}`)
23
),
24
import Micro
Micro
.
const catchTag: <"Bar", BarError, string, never, never>(k: "Bar", f: (e: BarError) => Micro.Micro<string, never, never>) => <A, R>(self: Micro.Micro<A, BarError, R>) => Micro.Micro<...> (+1 overload)

Recovers from the specified tagged error.

catchTag
("Bar", (
(parameter) error: BarError
error
) =>
25
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(`Bar error: ${
(parameter) error: BarError
error
.
(property) randomNumber: number
randomNumber
}`)
26
)
27
)
28
29
import Micro
Micro
.
const runPromise: <string, never>(effect: Micro.Micro<string, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program: Micro.Micro<string, never, never>
program
).
(method) Promise<string>.then<void, void>(onfulfilled?: ((value: string) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => void | PromiseLike<void>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
,
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.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` 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 code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
)
30
/*
31
Example Output (n < 0.2):
32
Foo error: Oh no!
33
*/

In the context of programming, a service refers to a reusable component or functionality that can be used by different parts of an application. Services are designed to provide specific capabilities and can be shared across multiple modules or components.

Services often encapsulate common tasks or operations that are needed by different parts of an application. They can handle complex operations, interact with external systems or APIs, manage data, or perform other specialized tasks.

Services are typically designed to be modular and decoupled from the rest of the application. This allows them to be easily maintained, tested, and replaced without affecting the overall functionality of the application.

To create a new service, you need two things:

  • A unique identifier.
  • A type describing the possible operations of the service.
1
import * as
import Context
Context
from "effect/Context"
2
import * as
import Micro
Micro
from "effect/Micro"
3
4
// Define a service using a unique identifier
5
class
class Random
Random
extends
import Context
Context
.
const Tag: <"MyRandomService">(id: "MyRandomService") => <Self, Shape>() => Context.TagClass<Self, "MyRandomService", Shape> namespace Tag
Tag
("MyRandomService")<
6
class Random
Random
,
7
{ readonly
(property) next: Micro.Micro<number, never, never>
next
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number> } // Operations
8
>() {}

Now that we have our service tag defined, let’s see how we can use it by building a simple program.

1
import * as
import Context
Context
from "effect/Context"
2
import * as
import Micro
Micro
from "effect/Micro"
3
4
// Define a service using a unique identifier
5
class
class Random
Random
extends
import Context
Context
.
const Tag: <"MyRandomService">(id: "MyRandomService") => <Self, Shape>() => Context.TagClass<Self, "MyRandomService", Shape> namespace Tag
Tag
("MyRandomService")<
6
class Random
Random
,
7
{ readonly
(property) next: Micro.Micro<number, never, never>
next
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number> } // Operations
8
>() {}
9
10
const
const program: Micro.Micro<void, never, Random>
program
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<{ readonly next: Micro.Micro<number>; }, never, Random>> | YieldWrap<Micro.Micro<number, never, never>>, void>(...args: [self: ...] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
11
// Access the Random service
12
const
const random: { readonly next: Micro.Micro<number>; }
random
= yield*
import Micro
Micro
.
const service: <Random, { readonly next: Micro.Micro<number>; }>(tag: Context.Tag<Random, { readonly next: Micro.Micro<number>; }>) => Micro.Micro<{ readonly next: Micro.Micro<number>; }, never, Random>

Access the given `Context.Tag` from the environment.

service
(
class Random
Random
)
13
14
// Retrieve a random number from the service
15
const
const randomNumber: number
randomNumber
= yield*
const random: { readonly next: Micro.Micro<number>; }
random
.
(property) next: Micro.Micro<number, never, never>
next
16
17
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
(`random number: ${
const randomNumber: number
randomNumber
}`)
18
})

It’s worth noting that the type of the program variable includes Random in the Requirements type parameter: Micro<void, never, Random>.

This indicates that our program requires the Random service to be provided in order to execute successfully.

To successfully execute the program, we need to provide an actual implementation of the Random service.

1
import * as
import Context
Context
from "effect/Context"
2
import * as
import Micro
Micro
from "effect/Micro"
3
4
// Define a service using a unique identifier
5
class
class Random
Random
extends
import Context
Context
.
const Tag: <"MyRandomService">(id: "MyRandomService") => <Self, Shape>() => Context.TagClass<Self, "MyRandomService", Shape> namespace Tag
Tag
("MyRandomService")<
6
class Random
Random
,
7
{ readonly
(property) next: Micro.Micro<number, never, never>
next
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number> } // Operations
8
>() {}
9
10
const
const program: Micro.Micro<void, never, Random>
program
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<{ readonly next: Micro.Micro<number>; }, never, Random>> | YieldWrap<Micro.Micro<number, never, never>>, void>(...args: [self: ...] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
11
// Access the Random service
12
const
const random: { readonly next: Micro.Micro<number>; }
random
= yield*
import Micro
Micro
.
const service: <Random, { readonly next: Micro.Micro<number>; }>(tag: Context.Tag<Random, { readonly next: Micro.Micro<number>; }>) => Micro.Micro<{ readonly next: Micro.Micro<number>; }, never, Random>

Access the given `Context.Tag` from the environment.

service
(
class Random
Random
)
13
14
// Retrieve a random number from the service
15
const
const randomNumber: number
randomNumber
= yield*
const random: { readonly next: Micro.Micro<number>; }
random
.
(property) next: Micro.Micro<number, never, never>
next
16
17
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
(`random number: ${
const randomNumber: number
randomNumber
}`)
18
})
19
20
// Provide the Random service implementation
21
const
const runnable: Micro.Micro<void, never, never>
runnable
=
import Micro
Micro
.
const provideService: <void, never, Random, Random, { next: Micro.Micro<number, never, never>; }>(self: Micro.Micro<void, never, Random>, tag: Context.Tag<Random, { next: Micro.Micro<...>; }>, service: { next: Micro.Micro<...>; }) => Micro.Micro<...> (+1 overload)

Add the provided service to the current context.

provideService
(
const program: Micro.Micro<void, never, Random>
program
,
class Random
Random
, {
22
(property) next: Micro.Micro<number, never, never>
next
:
import Micro
Micro
.
const sync: <number>(evaluate: LazyArg<number>) => Micro.Micro<number, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
(method) Math.random(): number

Returns a pseudorandom number between 0 and 1.

random
())
23
})
24
25
// Execute the program and print the random number
26
import Micro
Micro
.
const runPromise: <void, never>(effect: Micro.Micro<void, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const runnable: Micro.Micro<void, never, never>
runnable
)
27
/*
28
Example Output:
29
random number: 0.8241872233134417
30
*/

In simple terms, a MicroScope represents the lifetime of one or more resources. When a scope is closed, the resources associated with it are guaranteed to be released.

With the MicroScope data type, you can:

  • Add finalizers, which represent the release of a resource.
  • Close the scope, releasing all acquired resources and executing any added finalizers.
1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
= (
(parameter) message: string
message
: string) =>
4
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
(
(parameter) message: string
message
))
5
6
const
const program: Micro.Micro<void, never, never>
program
=
7
// create a new scope
8
import Micro
Micro
.
const scopeMake: Micro.Micro<Micro.MicroScope.Closeable, never, never>
scopeMake
.
(method) Pipeable.pipe<Micro.Micro<Micro.MicroScope.Closeable, never, never>, Micro.Micro<Micro.MicroScope.Closeable, never, never>, Micro.Micro<Micro.MicroScope.Closeable, never, never>, Micro.Micro<...>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<...>) => Micro.Micro<...>, bc: (_: Micro.Micro<...>) => Micro.Micro<...>, cd: (_: Micro.Micro<...>) => Micro.Micro<...>): Micro.Micro<...> (+21 overloads)
pipe
(
9
// add finalizer 1
10
import Micro
Micro
.
const tap: <Micro.MicroScope.Closeable, Micro.Micro<void, never, never>>(f: (a: Micro.MicroScope.Closeable) => Micro.Micro<void, never, never>) => <E, R>(self: Micro.Micro<...>) => Micro.Micro<...> (+3 overloads)

Execute a side effect from the success value of the `Micro` effect. It is similar to the `andThen` api, but the success value is ignored.

tap
((
(parameter) scope: Micro.MicroScope.Closeable
scope
) =>
11
(parameter) scope: Micro.MicroScope.Closeable
scope
.
(property) MicroScope.addFinalizer: (finalizer: (exit: Micro.MicroExit<unknown, unknown>) => Micro.Micro<void>) => Micro.Micro<void>
addFinalizer
(() =>
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
("finalizer 1"))
12
),
13
// add finalizer 2
14
import Micro
Micro
.
const tap: <Micro.MicroScope.Closeable, Micro.Micro<void, never, never>>(f: (a: Micro.MicroScope.Closeable) => Micro.Micro<void, never, never>) => <E, R>(self: Micro.Micro<...>) => Micro.Micro<...> (+3 overloads)

Execute a side effect from the success value of the `Micro` effect. It is similar to the `andThen` api, but the success value is ignored.

tap
((
(parameter) scope: Micro.MicroScope.Closeable
scope
) =>
15
(parameter) scope: Micro.MicroScope.Closeable
scope
.
(property) MicroScope.addFinalizer: (finalizer: (exit: Micro.MicroExit<unknown, unknown>) => Micro.Micro<void>) => Micro.Micro<void>
addFinalizer
(() =>
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
("finalizer 2"))
16
),
17
// close the scope
18
import Micro
Micro
.
const andThen: <Micro.MicroScope.Closeable, Micro.Micro<void, never, never>>(f: (a: Micro.MicroScope.Closeable) => Micro.Micro<void, never, never>) => <E, R>(self: Micro.Micro<...>) => Micro.Micro<...> (+3 overloads)

A more flexible version of `flatMap`, that combines `map` and `flatMap` into a single api. It also allows you to pass in a `Micro` effect directly, which will be executed after the current effect.

andThen
((
(parameter) scope: Micro.MicroScope.Closeable
scope
) =>
19
(parameter) scope: Micro.MicroScope.Closeable
scope
.
(property) MicroScope.Closeable.close: (exit: Micro.MicroExit<any, any>) => Micro.Micro<void>
close
(
import Micro
Micro
.
const exitSucceed: <string>(a: string) => Micro.MicroExit<string, never>
exitSucceed
("scope closed successfully"))
20
)
21
)
22
23
import Micro
Micro
.
const runPromise: <void, never>(effect: Micro.Micro<void, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program: Micro.Micro<void, never, never>
program
)
24
/*
25
Output:
26
finalizer 2 <-- finalizers are closed in reverse order
27
finalizer 1
28
*/

By default, when a MicroScope is closed, all finalizers added to that MicroScope are executed in the reverse order in which they were added. This approach makes sense because releasing resources in the reverse order of acquisition ensures that resources are properly closed.

For instance, if you open a network connection and then access a file on a remote server, you must close the file before closing the network connection. This sequence is critical to maintaining the ability to interact with the remote server.

The Micro.addFinalizer function provides a higher-level API for adding finalizers to the scope of a Micro value. These finalizers are guaranteed to execute when the associated scope is closed, and their behavior may depend on the MicroExit value with which the scope is closed.

Let’s observe how things behave in the event of success:

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
= (
(parameter) message: string
message
: string) =>
4
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
(
(parameter) message: string
message
))
5
6
const
const program: Micro.Micro<number, never, Micro.MicroScope>
program
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<void, never, Micro.MicroScope>>, number>(...args: [self: unknown, body: (this: unknown) => Generator<YieldWrap<Micro.Micro<void, never, Micro.MicroScope>>, number, never>] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
7
yield*
import Micro
Micro
.
const addFinalizer: (finalizer: (exit: Micro.MicroExit<unknown, unknown>) => Micro.Micro<void>) => Micro.Micro<void, never, Micro.MicroScope>

Add a finalizer to the current `MicroScope`.

addFinalizer
((
(parameter) exit: Micro.MicroExit<unknown, unknown>
exit
) =>
8
const consoleLog: (message: string) => Micro.Micro<void, never, never>
consoleLog
(`finalizer after ${
(parameter) exit: Micro.MicroExit<unknown, unknown>
exit
.
(property) _tag: "Right" | "Left"
_tag
}`)
9
)
10
return 1
11
})
12
13
const
const runnable: Micro.Micro<number, never, never>
runnable
=
import Micro
Micro
.
const scoped: <number, never, Micro.MicroScope>(self: Micro.Micro<number, never, Micro.MicroScope>) => Micro.Micro<number, never, never>

Provide a `MicroScope` to the given effect, closing it after the effect has finished executing.

scoped
(
const program: Micro.Micro<number, never, Micro.MicroScope>
program
)
14
15
import Micro
Micro
.
const runPromise: <number, never>(effect: Micro.Micro<number, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const runnable: Micro.Micro<number, never, never>
runnable
).
(method) Promise<number>.then<void, void>(onfulfilled?: ((value: number) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => void | PromiseLike<void>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
,
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.error(message?: any, ...optionalParams: any[]): void

Prints to `stderr` 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 code = 5; console.error('error #%d', code); // Prints: error #5, to stderr console.error('error', code); // Prints: error 5, to stderr ``` If formatting elements (e.g. `%d`) are not found in the first string then [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

error
)
16
/*
17
Output:
18
finalizer after Right
19
1
20
*/

Next, let’s explore how things behave in the event of a failure:

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const consoleLog: (message?: any, ...optionalParams: Array<any>) => Micro.Micro<void, never, never>
consoleLog
= (
(parameter) message: any
message
?: any, ...
(parameter) optionalParams: any[]
optionalParams
:
interface Array<T>
Array
<any>) =>
4
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
(
(parameter) message: any
message
, ...
(parameter) optionalParams: any[]
optionalParams
))
5
6
const
const program: Micro.Micro<never, string, Micro.MicroScope>
program
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<never, string, never>> | YieldWrap<Micro.Micro<void, never, Micro.MicroScope>>, never>(...args: [self: unknown, body: (this: unknown) => Generator<...>] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
7
yield*
import Micro
Micro
.
const addFinalizer: (finalizer: (exit: Micro.MicroExit<unknown, unknown>) => Micro.Micro<void>) => Micro.Micro<void, never, Micro.MicroScope>

Add a finalizer to the current `MicroScope`.

addFinalizer
((
(parameter) exit: Micro.MicroExit<unknown, unknown>
exit
) =>
8
const consoleLog: (message?: any, ...optionalParams: Array<any>) => Micro.Micro<void, never, never>
consoleLog
(`finalizer after ${
(parameter) exit: Micro.MicroExit<unknown, unknown>
exit
.
(property) _tag: "Right" | "Left"
_tag
}`)
9
)
10
return yield*
import Micro
Micro
.
const fail: <string>(e: string) => Micro.Micro<never, string, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
("Uh oh!")
11
})
12
13
const
const runnable: Micro.Micro<never, string, never>
runnable
=
import Micro
Micro
.
const scoped: <never, string, Micro.MicroScope>(self: Micro.Micro<never, string, Micro.MicroScope>) => Micro.Micro<never, string, never>

Provide a `MicroScope` to the given effect, closing it after the effect has finished executing.

scoped
(
const program: Micro.Micro<never, string, Micro.MicroScope>
program
)
14
15
import Micro
Micro
.
const runPromiseExit: <never, string>(effect: Micro.Micro<never, string, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const runnable: Micro.Micro<never, string, never>
runnable
).
(method) Promise<MicroExit<never, string>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<never, string>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
16
/*
17
Output:
18
finalizer after Left
19
{ _id: 'Either', _tag: 'Left', left: MicroCause.Fail: Uh oh! }
20
*/

We can define a resource using operators like Micro.acquireRelease(acquire, release), which allows us to create a scoped value from an acquire and release workflow.

Every acquire release requires three actions:

  • Acquiring Resource. An effect describing the acquisition of resource. For example, opening a file.
  • Using Resource. An effect describing the actual process to produce a result. For example, counting the number of lines in a file.
  • Releasing Resource. An effect describing the final step of releasing or cleaning up the resource. For example, closing a file.

The Micro.acquireRelease operator performs the acquire workflow uninterruptibly. This is important because if we allowed interruption during resource acquisition we could be interrupted when the resource was partially acquired.

The guarantee of the Micro.acquireRelease operator is that if the acquire workflow successfully completes execution then the release workflow is guaranteed to be run when the Scope is closed.

For example, let’s define a simple resource:

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
// Define the interface for the resource
4
interface
interface MyResource
MyResource
{
5
readonly
(property) MyResource.contents: string
contents
: string
6
readonly
(property) MyResource.close: () => Promise<void>
close
: () =>
interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<void>
7
}
8
9
// Simulate getting the resource
10
const
const getMyResource: () => Promise<MyResource>
getMyResource
= ():
interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<
interface MyResource
MyResource
> =>
11
var Promise: PromiseConstructor

Represents the completion of an asynchronous operation

Promise
.
(method) PromiseConstructor.resolve<{ contents: string; close: () => Promise<void>; }>(value: { contents: string; close: () => Promise<void>; }): Promise<{ contents: string; close: () => Promise<void>; }> (+2 overloads)

Creates a new resolved promise for the provided value.

resolve
({
12
(property) contents: string
contents
: "lorem ipsum",
13
(property) close: () => Promise<void>
close
: () =>
14
new
var Promise: PromiseConstructor new <void>(executor: (resolve: (value: void | PromiseLike<void>) => void, reject: (reason?: any) => void) => void) => Promise<void>

Creates a new Promise.

Promise
((
(parameter) resolve: (value: void | PromiseLike<void>) => void
resolve
) => {
15
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
("Resource released")
16
(parameter) resolve: (value: void | PromiseLike<void>) => void
resolve
()
17
})
18
})
19
20
// Define the acquisition of the resource with error handling
21
const
const acquire: Micro.Micro<MyResource, Error, never>
acquire
=
import Micro
Micro
.
const tryPromise: <MyResource, Error>(options: { readonly try: (signal: AbortSignal) => PromiseLike<MyResource>; readonly catch: (error: unknown) => Error; }) => Micro.Micro<...>

Wrap a `Promise` into a `Micro` effect. Any errors will be caught and converted into a specific error type.

tryPromise
({
22
(property) try: (signal: AbortSignal) => PromiseLike<MyResource>
try
: () =>
23
const getMyResource: () => Promise<MyResource>
getMyResource
().
(method) Promise<MyResource>.then<MyResource, never>(onfulfilled?: ((value: MyResource) => MyResource | PromiseLike<MyResource>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<...>) | ... 1 more ... | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
((
(parameter) res: MyResource
res
) => {
24
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
("Resource acquired")
25
return
(parameter) res: MyResource
res
26
}),
27
(property) catch: (error: unknown) => Error
catch
: () => new
var Error: ErrorConstructor new (message?: string) => Error
Error
("getMyResourceError")
28
})
29
30
// Define the release of the resource
31
const
const release: (res: MyResource) => Micro.Micro<void, never, never>
release
= (
(parameter) res: MyResource
res
:
interface MyResource
MyResource
) =>
import Micro
Micro
.
const promise: <void>(evaluate: (signal: AbortSignal) => PromiseLike<void>) => Micro.Micro<void, never, never>

Wrap a `Promise` into a `Micro` effect. Any errors will result in a `CauseDie`.

promise
(() =>
(parameter) res: MyResource
res
.
(property) MyResource.close: () => Promise<void>
close
())
32
33
const
const resource: Micro.Micro<MyResource, Error, Micro.MicroScope>
resource
=
import Micro
Micro
.
const acquireRelease: <MyResource, Error, never>(acquire: Micro.Micro<MyResource, Error, never>, release: (a: MyResource, exit: Micro.MicroExit<unknown, unknown>) => Micro.Micro<void>) => Micro.Micro<...>

Create a resource with a cleanup `Micro` effect, ensuring the cleanup is executed when the `MicroScope` is closed.

acquireRelease
(
const acquire: Micro.Micro<MyResource, Error, never>
acquire
,
const release: (res: MyResource) => Micro.Micro<void, never, never>
release
)
34
35
const
const program: Micro.Micro<void, Error, never>
program
=
import Micro
Micro
.
const scoped: <void, Error, Micro.MicroScope>(self: Micro.Micro<void, Error, Micro.MicroScope>) => Micro.Micro<void, Error, never>

Provide a `MicroScope` to the given effect, closing it after the effect has finished executing.

scoped
(
36
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<MyResource, Error, Micro.MicroScope>>, void>(...args: [self: unknown, body: (this: unknown) => Generator<YieldWrap<Micro.Micro<MyResource, Error, Micro.MicroScope>>, void, never>] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
37
const
const res: MyResource
res
= yield*
const resource: Micro.Micro<MyResource, Error, Micro.MicroScope>
resource
38
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
(`content is ${
const res: MyResource
res
.
(property) MyResource.contents: string
contents
}`)
39
})
40
)
41
42
import Micro
Micro
.
const runPromise: <void, Error>(effect: Micro.Micro<void, Error, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program: Micro.Micro<void, Error, never>
program
)
43
/*
44
Resource acquired
45
content is lorem ipsum
46
Resource released
47
*/

The Micro.scoped operator removes the MicroScope from the context, indicating that there are no longer any resources used by this workflow which require a scope.

The Micro.acquireUseRelease(acquire, use, release) function is a specialized version of the Micro.acquireRelease function that simplifies resource management by automatically handling the scoping of resources.

The main difference is that acquireUseRelease eliminates the need to manually call Micro.scoped to manage the resource’s scope. It has additional knowledge about when you are done using the resource created with the acquire step. This is achieved by providing a use argument, which represents the function that operates on the acquired resource. As a result, acquireUseRelease can automatically determine when it should execute the release step.

Here’s an example that demonstrates the usage of acquireUseRelease:

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
// Define the interface for the resource
4
interface
interface MyResource
MyResource
{
5
readonly
(property) MyResource.contents: string
contents
: string
6
readonly
(property) MyResource.close: () => Promise<void>
close
: () =>
interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<void>
7
}
8
9
// Simulate getting the resource
10
const
const getMyResource: () => Promise<MyResource>
getMyResource
= ():
interface Promise<T>

Represents the completion of an asynchronous operation

Promise
<
interface MyResource
MyResource
> =>
11
var Promise: PromiseConstructor

Represents the completion of an asynchronous operation

Promise
.
(method) PromiseConstructor.resolve<{ contents: string; close: () => Promise<void>; }>(value: { contents: string; close: () => Promise<void>; }): Promise<{ contents: string; close: () => Promise<void>; }> (+2 overloads)

Creates a new resolved promise for the provided value.

resolve
({
12
(property) contents: string
contents
: "lorem ipsum",
13
(property) close: () => Promise<void>
close
: () =>
14
new
var Promise: PromiseConstructor new <void>(executor: (resolve: (value: void | PromiseLike<void>) => void, reject: (reason?: any) => void) => void) => Promise<void>

Creates a new Promise.

Promise
((
(parameter) resolve: (value: void | PromiseLike<void>) => void
resolve
) => {
15
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
("Resource released")
16
(parameter) resolve: (value: void | PromiseLike<void>) => void
resolve
()
17
})
18
})
19
20
// Define the acquisition of the resource with error handling
21
const
const acquire: Micro.Micro<MyResource, Error, never>
acquire
=
import Micro
Micro
.
const tryPromise: <MyResource, Error>(options: { readonly try: (signal: AbortSignal) => PromiseLike<MyResource>; readonly catch: (error: unknown) => Error; }) => Micro.Micro<...>

Wrap a `Promise` into a `Micro` effect. Any errors will be caught and converted into a specific error type.

tryPromise
({
22
(property) try: (signal: AbortSignal) => PromiseLike<MyResource>
try
: () =>
23
const getMyResource: () => Promise<MyResource>
getMyResource
().
(method) Promise<MyResource>.then<MyResource, never>(onfulfilled?: ((value: MyResource) => MyResource | PromiseLike<MyResource>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<...>) | ... 1 more ... | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
((
(parameter) res: MyResource
res
) => {
24
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
("Resource acquired")
25
return
(parameter) res: MyResource
res
26
}),
27
(property) catch: (error: unknown) => Error
catch
: () => new
var Error: ErrorConstructor new (message?: string) => Error
Error
("getMyResourceError")
28
})
29
30
// Define the release of the resource
31
const
const release: (res: MyResource) => Micro.Micro<void, never, never>
release
= (
(parameter) res: MyResource
res
:
interface MyResource
MyResource
) =>
import Micro
Micro
.
const promise: <void>(evaluate: (signal: AbortSignal) => PromiseLike<void>) => Micro.Micro<void, never, never>

Wrap a `Promise` into a `Micro` effect. Any errors will result in a `CauseDie`.

promise
(() =>
(parameter) res: MyResource
res
.
(property) MyResource.close: () => Promise<void>
close
())
32
33
const
const use: (res: MyResource) => Micro.Micro<void, never, never>
use
= (
(parameter) res: MyResource
res
:
interface MyResource
MyResource
) =>
34
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
(`content is ${
(parameter) res: MyResource
res
.
(property) MyResource.contents: string
contents
}`))
35
36
const
const program: Micro.Micro<void, Error, never>
program
=
import Micro
Micro
.
const acquireUseRelease: <MyResource, Error, never, void, never, never, never, never>(acquire: Micro.Micro<MyResource, Error, never>, use: (a: MyResource) => Micro.Micro<...>, release: (a: MyResource, exit: Micro.MicroExit<...>) => Micro.Micro<...>) => Micro.Micro<...>

Acquire a resource, use it, and then release the resource when the `use` effect has completed.

acquireUseRelease
(
const acquire: Micro.Micro<MyResource, Error, never>
acquire
,
const use: (res: MyResource) => Micro.Micro<void, never, never>
use
,
const release: (res: MyResource) => Micro.Micro<void, never, never>
release
)
37
38
import Micro
Micro
.
const runPromise: <void, Error>(effect: Micro.Micro<void, Error, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program: Micro.Micro<void, Error, never>
program
)
39
/*
40
Resource acquired
41
content is lorem ipsum
42
Resource released
43
*/

The Micro.repeat function returns a new effect that repeats the given effect according to a specified schedule or until the first failure.

Success Example

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const action: Micro.Micro<void, never, never>
action
=
import Micro
Micro
.
const sync: <void>(evaluate: LazyArg<void>) => Micro.Micro<void, never, never>

Creates a `Micro` effect that will succeed with the lazily evaluated value. If the evaluation of the value throws an error, the effect will fail with `CauseDie`.

sync
(() =>
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
("success"))
4
5
const
const policy: Micro.MicroSchedule
policy
=
import Micro
Micro
.
const scheduleAddDelay: (self: Micro.MicroSchedule, f: () => number) => Micro.MicroSchedule (+1 overload)

Returns a new `MicroSchedule` with an added calculated delay to each delay returned by this schedule.

scheduleAddDelay
(
import Micro
Micro
.
const scheduleRecurs: (n: number) => Micro.MicroSchedule

Create a `MicroSchedule` that will stop repeating after the specified number of attempts.

scheduleRecurs
(2), () => 100)
6
7
const
const program: Micro.Micro<void, never, never>
program
=
import Micro
Micro
.
const repeat: <void, never, never>(self: Micro.Micro<void, never, never>, options?: { while?: Predicate<void> | undefined; times?: number | undefined; schedule?: Micro.MicroSchedule | undefined; } | undefined) => Micro.Micro<...> (+1 overload)

Repeat the given `Micro` effect using the provided options. Only successful results will be repeated.

repeat
(
const action: Micro.Micro<void, never, never>
action
, {
(property) schedule?: Micro.MicroSchedule | undefined
schedule
:
const policy: Micro.MicroSchedule
policy
})
8
9
import Micro
Micro
.
const runPromise: <void, never>(effect: Micro.Micro<void, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program: Micro.Micro<void, never, never>
program
).
(method) Promise<void>.then<void, never>(onfulfilled?: ((value: void) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
((
(parameter) n: void
n
) =>
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
(`repetitions: ${
(parameter) n: void
n
}`))
10
/*
11
Output:
12
success
13
success
14
success
15
*/

Failure Example

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
let
let count: number
count
= 0
4
5
// Define an async effect that simulates an action with possible failures
6
const
const action: Micro.Micro<string, string, never>
action
=
import Micro
Micro
.
const async: <string, string, never>(register: (resume: (effect: Micro.Micro<string, string, never>) => void, signal: AbortSignal) => void | Micro.Micro<void, never, never>) => Micro.Micro<...>

Create a `Micro` effect from an asynchronous computation. You can return a cleanup effect that will be run when the effect is aborted. It is also passed an `AbortSignal` that is triggered when the effect is aborted.

async
<string, string>((
(parameter) resume: (effect: Micro.Micro<string, string, never>) => void
resume
) => {
7
if (
let count: number
count
> 1) {
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
("failure")
9
(parameter) resume: (effect: Micro.Micro<string, string, never>) => void
resume
(
import Micro
Micro
.
const fail: <string>(e: string) => Micro.Micro<never, string, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
("Uh oh!"))
10
} else {
11
let count: number
count
++
12
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
("success")
13
(parameter) resume: (effect: Micro.Micro<string, string, never>) => void
resume
(
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
("yay!"))
14
}
15
})
16
17
const
const policy: Micro.MicroSchedule
policy
=
import Micro
Micro
.
const scheduleAddDelay: (self: Micro.MicroSchedule, f: () => number) => Micro.MicroSchedule (+1 overload)

Returns a new `MicroSchedule` with an added calculated delay to each delay returned by this schedule.

scheduleAddDelay
(
import Micro
Micro
.
const scheduleRecurs: (n: number) => Micro.MicroSchedule

Create a `MicroSchedule` that will stop repeating after the specified number of attempts.

scheduleRecurs
(2), () => 100)
18
19
const
const program: Micro.Micro<string, string, never>
program
=
import Micro
Micro
.
const repeat: <string, string, never>(self: Micro.Micro<string, string, never>, options?: { while?: Predicate<string> | undefined; times?: number | undefined; schedule?: Micro.MicroSchedule | undefined; } | undefined) => Micro.Micro<...> (+1 overload)

Repeat the given `Micro` effect using the provided options. Only successful results will be repeated.

repeat
(
const action: Micro.Micro<string, string, never>
action
, {
(property) schedule?: Micro.MicroSchedule | undefined
schedule
:
const policy: Micro.MicroSchedule
policy
})
20
21
import Micro
Micro
.
const runPromiseExit: <string, string>(effect: Micro.Micro<string, string, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const program: Micro.Micro<string, string, never>
program
).
(method) Promise<MicroExit<string, string>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<string, string>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
22
/*
23
Output:
24
success
25
success
26
failure
27
{ _id: 'Either', _tag: 'Left', left: MicroCause.Fail: Uh oh! }
28
*/

To demonstrate the functionality of different schedules, we will be working with the following helper:

1
import type * as
import Micro
Micro
from "effect/Micro"
2
import * as
import Option
Option
from "effect/Option"
3
4
const
const dryRun: (schedule: Micro.MicroSchedule, maxAttempt?: number) => Array<number>
dryRun
= (
5
(parameter) schedule: Micro.MicroSchedule
schedule
:
import Micro
Micro
.
type MicroSchedule = (attempt: number, elapsed: number) => Option.Option<number>

The `MicroSchedule` type represents a function that can be used to calculate the delay between repeats. The function takes the current attempt number and the elapsed time since the first attempt, and returns the delay for the next attempt. If the function returns `None`, the repetition will stop.

MicroSchedule
,
6
(parameter) maxAttempt: number
maxAttempt
: number = 7
7
):
interface Array<T>
Array
<number> => {
8
let
let attempt: number
attempt
= 1
9
let
let elapsed: number
elapsed
= 0
10
let
let duration: Option.Option<number>
duration
=
(parameter) schedule: (attempt: number, elapsed: number) => Option.Option<number>
schedule
(
let attempt: number
attempt
,
let elapsed: number
elapsed
)
11
const
const out: number[]
out
:
interface Array<T>
Array
<number> = []
12
while (
import Option
Option
.
const isSome: <number>(self: Option.Option<number>) => self is Option.Some<number>

Determine if a `Option` is a `Some`.

isSome
(
let duration: Option.Option<number>
duration
) &&
let attempt: number
attempt
<=
(parameter) maxAttempt: number
maxAttempt
) {
13
const
const value: number
value
=
let duration: Option.Some<number>
duration
.
(property) Some<number>.value: number
value
14
let attempt: number
attempt
++
15
let elapsed: number
elapsed
+=
const value: number
value
16
const out: number[]
out
.
(method) Array<number>.push(...items: number[]): number

Appends new elements to the end of an array, and returns the new length of the array.

push
(
const value: number
value
)
17
let duration: Option.Option<number>
duration
=
(parameter) schedule: (attempt: number, elapsed: number) => Option.Option<number>
schedule
(
let attempt: number
attempt
,
let elapsed: number
elapsed
)
18
}
19
return
const out: number[]
out
20
}

A schedule that recurs continuously, each repetition spaced the specified duration from the last run.

1
import * as
import Micro
Micro
from "effect/Micro"
2
import * as
import Option
Option
from "effect/Option"
3
17 collapsed lines
4
const
const dryRun: (schedule: Micro.MicroSchedule, maxAttempt?: number) => Array<number>
dryRun
= (
5
(parameter) schedule: Micro.MicroSchedule
schedule
:
import Micro
Micro
.
type MicroSchedule = (attempt: number, elapsed: number) => Option.Option<number>

The `MicroSchedule` type represents a function that can be used to calculate the delay between repeats. The function takes the current attempt number and the elapsed time since the first attempt, and returns the delay for the next attempt. If the function returns `None`, the repetition will stop.

MicroSchedule
,
6
(parameter) maxAttempt: number
maxAttempt
: number = 7
7
):
interface Array<T>
Array
<number> => {
8
let
let attempt: number
attempt
= 1
9
let
let elapsed: number
elapsed
= 0
10
let
let duration: Option.Option<number>
duration
=
(parameter) schedule: (attempt: number, elapsed: number) => Option.Option<number>
schedule
(
let attempt: number
attempt
,
let elapsed: number
elapsed
)
11
const
const out: number[]
out
:
interface Array<T>
Array
<number> = []
12
while (
import Option
Option
.
const isSome: <number>(self: Option.Option<number>) => self is Option.Some<number>

Determine if a `Option` is a `Some`.

isSome
(
let duration: Option.Option<number>
duration
) &&
let attempt: number
attempt
<=
(parameter) maxAttempt: number
maxAttempt
) {
13
const
const value: number
value
=
let duration: Option.Some<number>
duration
.
(property) Some<number>.value: number
value
14
let attempt: number
attempt
++
15
let elapsed: number
elapsed
+=
const value: number
value
16
const out: number[]
out
.
(method) Array<number>.push(...items: number[]): number

Appends new elements to the end of an array, and returns the new length of the array.

push
(
const value: number
value
)
17
let duration: Option.Option<number>
duration
=
(parameter) schedule: (attempt: number, elapsed: number) => Option.Option<number>
schedule
(
let attempt: number
attempt
,
let elapsed: number
elapsed
)
18
}
19
return
const out: number[]
out
20
}
21
22
const
const policy: Micro.MicroSchedule
policy
=
import Micro
Micro
.
const scheduleSpaced: (millis: number) => Micro.MicroSchedule

Create a `MicroSchedule` that will generate a constant delay.

scheduleSpaced
(10)
23
24
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 dryRun: (schedule: Micro.MicroSchedule, maxAttempt?: number) => Array<number>
dryRun
(
const policy: Micro.MicroSchedule
policy
))
25
/*
26
Output:
27
[
28
10, 10, 10, 10,
29
10, 10, 10
30
]
31
*/

A schedule that recurs using exponential backoff.

1
import * as
import Micro
Micro
from "effect/Micro"
2
import * as
import Option
Option
from "effect/Option"
3
17 collapsed lines
4
const
const dryRun: (schedule: Micro.MicroSchedule, maxAttempt?: number) => Array<number>
dryRun
= (
5
(parameter) schedule: Micro.MicroSchedule
schedule
:
import Micro
Micro
.
type MicroSchedule = (attempt: number, elapsed: number) => Option.Option<number>

The `MicroSchedule` type represents a function that can be used to calculate the delay between repeats. The function takes the current attempt number and the elapsed time since the first attempt, and returns the delay for the next attempt. If the function returns `None`, the repetition will stop.

MicroSchedule
,
6
(parameter) maxAttempt: number
maxAttempt
: number = 7
7
):
interface Array<T>
Array
<number> => {
8
let
let attempt: number
attempt
= 1
9
let
let elapsed: number
elapsed
= 0
10
let
let duration: Option.Option<number>
duration
=
(parameter) schedule: (attempt: number, elapsed: number) => Option.Option<number>
schedule
(
let attempt: number
attempt
,
let elapsed: number
elapsed
)
11
const
const out: number[]
out
:
interface Array<T>
Array
<number> = []
12
while (
import Option
Option
.
const isSome: <number>(self: Option.Option<number>) => self is Option.Some<number>

Determine if a `Option` is a `Some`.

isSome
(
let duration: Option.Option<number>
duration
) &&
let attempt: number
attempt
<=
(parameter) maxAttempt: number
maxAttempt
) {
13
const
const value: number
value
=
let duration: Option.Some<number>
duration
.
(property) Some<number>.value: number
value
14
let attempt: number
attempt
++
15
let elapsed: number
elapsed
+=
const value: number
value
16
const out: number[]
out
.
(method) Array<number>.push(...items: number[]): number

Appends new elements to the end of an array, and returns the new length of the array.

push
(
const value: number
value
)
17
let duration: Option.Option<number>
duration
=
(parameter) schedule: (attempt: number, elapsed: number) => Option.Option<number>
schedule
(
let attempt: number
attempt
,
let elapsed: number
elapsed
)
18
}
19
return
const out: number[]
out
20
}
21
22
const
const policy: Micro.MicroSchedule
policy
=
import Micro
Micro
.
const scheduleExponential: (baseMillis: number, factor?: number) => Micro.MicroSchedule

Create a `MicroSchedule` that will generate a delay with an exponential backoff.

scheduleExponential
(10)
23
24
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 dryRun: (schedule: Micro.MicroSchedule, maxAttempt?: number) => Array<number>
dryRun
(
const policy: Micro.MicroSchedule
policy
))
25
/*
26
Output:
27
[
28
20, 40, 80,
29
160, 320, 640,
30
1280
31
]
32
*/

Combines two schedules through union, by recurring if either schedule wants to recur, using the minimum of the two delays between recurrences.

1
import * as
import Micro
Micro
from "effect/Micro"
2
import * as
import Option
Option
from "effect/Option"
3
17 collapsed lines
4
const
const dryRun: (schedule: Micro.MicroSchedule, maxAttempt?: number) => Array<number>
dryRun
= (
5
(parameter) schedule: Micro.MicroSchedule
schedule
:
import Micro
Micro
.
type MicroSchedule = (attempt: number, elapsed: number) => Option.Option<number>

The `MicroSchedule` type represents a function that can be used to calculate the delay between repeats. The function takes the current attempt number and the elapsed time since the first attempt, and returns the delay for the next attempt. If the function returns `None`, the repetition will stop.

MicroSchedule
,
6
(parameter) maxAttempt: number
maxAttempt
: number = 7
7
):
interface Array<T>
Array
<number> => {
8
let
let attempt: number
attempt
= 1
9
let
let elapsed: number
elapsed
= 0
10
let
let duration: Option.Option<number>
duration
=
(parameter) schedule: (attempt: number, elapsed: number) => Option.Option<number>
schedule
(
let attempt: number
attempt
,
let elapsed: number
elapsed
)
11
const
const out: number[]
out
:
interface Array<T>
Array
<number> = []
12
while (
import Option
Option
.
const isSome: <number>(self: Option.Option<number>) => self is Option.Some<number>

Determine if a `Option` is a `Some`.

isSome
(
let duration: Option.Option<number>
duration
) &&
let attempt: number
attempt
<=
(parameter) maxAttempt: number
maxAttempt
) {
13
const
const value: number
value
=
let duration: Option.Some<number>
duration
.
(property) Some<number>.value: number
value
14
let attempt: number
attempt
++
15
let elapsed: number
elapsed
+=
const value: number
value
16
const out: number[]
out
.
(method) Array<number>.push(...items: number[]): number

Appends new elements to the end of an array, and returns the new length of the array.

push
(
const value: number
value
)
17
let duration: Option.Option<number>
duration
=
(parameter) schedule: (attempt: number, elapsed: number) => Option.Option<number>
schedule
(
let attempt: number
attempt
,
let elapsed: number
elapsed
)
18
}
19
return
const out: number[]
out
20
}
21
22
const
const policy: Micro.MicroSchedule
policy
=
import Micro
Micro
.
const scheduleUnion: (self: Micro.MicroSchedule, that: Micro.MicroSchedule) => Micro.MicroSchedule (+1 overload)

Combines two `MicroSchedule`s, by recurring if either schedule wants to recur, using the minimum of the two durations between recurrences.

scheduleUnion
(
23
import Micro
Micro
.
const scheduleExponential: (baseMillis: number, factor?: number) => Micro.MicroSchedule

Create a `MicroSchedule` that will generate a delay with an exponential backoff.

scheduleExponential
(10),
24
import Micro
Micro
.
const scheduleSpaced: (millis: number) => Micro.MicroSchedule

Create a `MicroSchedule` that will generate a constant delay.

scheduleSpaced
(300)
25
)
26
27
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 dryRun: (schedule: Micro.MicroSchedule, maxAttempt?: number) => Array<number>
dryRun
(
const policy: Micro.MicroSchedule
policy
))
28
/*
29
Output:
30
[
31
20, < exponential
32
40,
33
80,
34
160,
35
300, < spaced
36
300,
37
300
38
]
39
*/

Combines two schedules through the intersection, by recurring only if both schedules want to recur, using the maximum of the two delays between recurrences.

1
import * as
import Micro
Micro
from "effect/Micro"
2
import * as
import Option
Option
from "effect/Option"
3
17 collapsed lines
4
const
const dryRun: (schedule: Micro.MicroSchedule, maxAttempt?: number) => Array<number>
dryRun
= (
5
(parameter) schedule: Micro.MicroSchedule
schedule
:
import Micro
Micro
.
type MicroSchedule = (attempt: number, elapsed: number) => Option.Option<number>

The `MicroSchedule` type represents a function that can be used to calculate the delay between repeats. The function takes the current attempt number and the elapsed time since the first attempt, and returns the delay for the next attempt. If the function returns `None`, the repetition will stop.

MicroSchedule
,
6
(parameter) maxAttempt: number
maxAttempt
: number = 7
7
):
interface Array<T>
Array
<number> => {
8
let
let attempt: number
attempt
= 1
9
let
let elapsed: number
elapsed
= 0
10
let
let duration: Option.Option<number>
duration
=
(parameter) schedule: (attempt: number, elapsed: number) => Option.Option<number>
schedule
(
let attempt: number
attempt
,
let elapsed: number
elapsed
)
11
const
const out: number[]
out
:
interface Array<T>
Array
<number> = []
12
while (
import Option
Option
.
const isSome: <number>(self: Option.Option<number>) => self is Option.Some<number>

Determine if a `Option` is a `Some`.

isSome
(
let duration: Option.Option<number>
duration
) &&
let attempt: number
attempt
<=
(parameter) maxAttempt: number
maxAttempt
) {
13
const
const value: number
value
=
let duration: Option.Some<number>
duration
.
(property) Some<number>.value: number
value
14
let attempt: number
attempt
++
15
let elapsed: number
elapsed
+=
const value: number
value
16
const out: number[]
out
.
(method) Array<number>.push(...items: number[]): number

Appends new elements to the end of an array, and returns the new length of the array.

push
(
const value: number
value
)
17
let duration: Option.Option<number>
duration
=
(parameter) schedule: (attempt: number, elapsed: number) => Option.Option<number>
schedule
(
let attempt: number
attempt
,
let elapsed: number
elapsed
)
18
}
19
return
const out: number[]
out
20
}
21
22
const
const policy: Micro.MicroSchedule
policy
=
import Micro
Micro
.
const scheduleIntersect: (self: Micro.MicroSchedule, that: Micro.MicroSchedule) => Micro.MicroSchedule (+1 overload)

Combines two `MicroSchedule`s, by recurring only if both schedules want to recur, using the maximum of the two durations between recurrences.

scheduleIntersect
(
23
import Micro
Micro
.
const scheduleExponential: (baseMillis: number, factor?: number) => Micro.MicroSchedule

Create a `MicroSchedule` that will generate a delay with an exponential backoff.

scheduleExponential
(10),
24
import Micro
Micro
.
const scheduleSpaced: (millis: number) => Micro.MicroSchedule

Create a `MicroSchedule` that will generate a constant delay.

scheduleSpaced
(300)
25
)
26
27
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 dryRun: (schedule: Micro.MicroSchedule, maxAttempt?: number) => Array<number>
dryRun
(
const policy: Micro.MicroSchedule
policy
))
28
/*
29
Output:
30
[
31
300, < spaced
32
300,
33
300,
34
300,
35
320, < exponential
36
640,
37
1280
38
]
39
*/

One of the fundamental ways to create a fiber is by forking an existing effect. When you fork an effect, it starts executing the effect on a new fiber, giving you a reference to this newly-created fiber.

The following code demonstrates how to create a single fiber using the Micro.fork function. This fiber will execute the function fib(100) independently of the main fiber:

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const fib: (n: number) => Micro.Micro<number>
fib
= (
(parameter) n: number
n
: number):
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number> =>
4
import Micro
Micro
.
const suspend: <number, never, never>(evaluate: LazyArg<Micro.Micro<number, never, never>>) => Micro.Micro<number, never, never>

Lazily creates a `Micro` effect from the given side-effect.

suspend
(() => {
5
if (
(parameter) n: number
n
<= 1) {
6
return
import Micro
Micro
.
const succeed: <number>(a: number) => Micro.Micro<number, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(
(parameter) n: number
n
)
7
}
8
return
const fib: (n: number) => Micro.Micro<number>
fib
(
(parameter) n: number
n
- 1).
(method) Pipeable.pipe<Micro.Micro<number, never, never>, Micro.Micro<number, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<number, never, never>) => Micro.Micro<number, never, never>): Micro.Micro<...> (+21 overloads)
pipe
(
import Micro
Micro
.
const zipWith: <number, never, never, number, number>(that: Micro.Micro<number, never, never>, f: (a: number, b: number) => number, options?: { readonly concurrent?: boolean | undefined; }) => <E, R>(self: Micro.Micro<...>) => Micro.Micro<...> (+1 overload)

The `Micro.zipWith` function combines two `Micro` effects and allows you to apply a function to the results of the combined effects, transforming them into a single value.

zipWith
(
const fib: (n: number) => Micro.Micro<number>
fib
(
(parameter) n: number
n
- 2), (
(parameter) a: number
a
,
(parameter) b: number
b
) =>
(parameter) a: number
a
+
(parameter) b: number
b
))
9
})
10
11
const
const fib10Fiber: Micro.Micro<Micro.Handle<number, never>, never, never>
fib10Fiber
=
import Micro
Micro
.
const fork: <number, never, never>(self: Micro.Micro<number, never, never>) => Micro.Micro<Micro.Handle<number, never>, never, never>

Run the `Micro` effect in a new `Handle` that can be awaited, joined, or aborted. When the parent `Micro` finishes, this `Micro` will be aborted.

fork
(
const fib: (n: number) => Micro.Micro<number>
fib
(10))

A common operation with fibers is joining them using the .join property. This property returns a Micro that will succeed or fail based on the outcome of the fiber it joins:

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const fib: (n: number) => Micro.Micro<number>
fib
= (
(parameter) n: number
n
: number):
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number> =>
4
import Micro
Micro
.
const suspend: <number, never, never>(evaluate: LazyArg<Micro.Micro<number, never, never>>) => Micro.Micro<number, never, never>

Lazily creates a `Micro` effect from the given side-effect.

suspend
(() => {
5
if (
(parameter) n: number
n
<= 1) {
6
return
import Micro
Micro
.
const succeed: <number>(a: number) => Micro.Micro<number, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(
(parameter) n: number
n
)
7
}
8
return
const fib: (n: number) => Micro.Micro<number>
fib
(
(parameter) n: number
n
- 1).
(method) Pipeable.pipe<Micro.Micro<number, never, never>, Micro.Micro<number, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<number, never, never>) => Micro.Micro<number, never, never>): Micro.Micro<...> (+21 overloads)
pipe
(
import Micro
Micro
.
const zipWith: <number, never, never, number, number>(that: Micro.Micro<number, never, never>, f: (a: number, b: number) => number, options?: { readonly concurrent?: boolean | undefined; }) => <E, R>(self: Micro.Micro<...>) => Micro.Micro<...> (+1 overload)

The `Micro.zipWith` function combines two `Micro` effects and allows you to apply a function to the results of the combined effects, transforming them into a single value.

zipWith
(
const fib: (n: number) => Micro.Micro<number>
fib
(
(parameter) n: number
n
- 2), (
(parameter) a: number
a
,
(parameter) b: number
b
) =>
(parameter) a: number
a
+
(parameter) b: number
b
))
9
})
10
11
const
const fib10Fiber: Micro.Micro<Micro.Handle<number, never>, never, never>
fib10Fiber
=
import Micro
Micro
.
const fork: <number, never, never>(self: Micro.Micro<number, never, never>) => Micro.Micro<Micro.Handle<number, never>, never, never>

Run the `Micro` effect in a new `Handle` that can be awaited, joined, or aborted. When the parent `Micro` finishes, this `Micro` will be aborted.

fork
(
const fib: (n: number) => Micro.Micro<number>
fib
(10))
12
13
const
const program: Micro.Micro<void, never, never>
program
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<Micro.Handle<number, never>, never, never>> | YieldWrap<Micro.Micro<number, never, never>>, void>(...args: [self: ...] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
14
const
const fiber: Micro.Handle<number, never>
fiber
= yield*
const fib10Fiber: Micro.Micro<Micro.Handle<number, never>, never, never>
fib10Fiber
15
const
const n: number
n
= yield*
const fiber: Micro.Handle<number, never>
fiber
.
(property) Handle<number, never>.join: Micro.Micro<number, never, never>
join
16
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 n: number
n
)
17
})
18
19
import Micro
Micro
.
const runPromise: <void, never>(effect: Micro.Micro<void, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program: Micro.Micro<void, never, never>
program
) // 55

Another useful property for fibers is .await. This property returns an effect containing a MicroExit value, which provides detailed information about how the fiber completed.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const fib: (n: number) => Micro.Micro<number>
fib
= (
(parameter) n: number
n
: number):
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never> namespace Micro

A lightweight alternative to the `Effect` data type, with a subset of the functionality.

Micro
<number> =>
4
import Micro
Micro
.
const suspend: <number, never, never>(evaluate: LazyArg<Micro.Micro<number, never, never>>) => Micro.Micro<number, never, never>

Lazily creates a `Micro` effect from the given side-effect.

suspend
(() => {
5
if (
(parameter) n: number
n
<= 1) {
6
return
import Micro
Micro
.
const succeed: <number>(a: number) => Micro.Micro<number, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
(
(parameter) n: number
n
)
7
}
8
return
const fib: (n: number) => Micro.Micro<number>
fib
(
(parameter) n: number
n
- 1).
(method) Pipeable.pipe<Micro.Micro<number, never, never>, Micro.Micro<number, never, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<number, never, never>) => Micro.Micro<number, never, never>): Micro.Micro<...> (+21 overloads)
pipe
(
import Micro
Micro
.
const zipWith: <number, never, never, number, number>(that: Micro.Micro<number, never, never>, f: (a: number, b: number) => number, options?: { readonly concurrent?: boolean | undefined; }) => <E, R>(self: Micro.Micro<...>) => Micro.Micro<...> (+1 overload)

The `Micro.zipWith` function combines two `Micro` effects and allows you to apply a function to the results of the combined effects, transforming them into a single value.

zipWith
(
const fib: (n: number) => Micro.Micro<number>
fib
(
(parameter) n: number
n
- 2), (
(parameter) a: number
a
,
(parameter) b: number
b
) =>
(parameter) a: number
a
+
(parameter) b: number
b
))
9
})
10
11
const
const fib10Fiber: Micro.Micro<Micro.Handle<number, never>, never, never>
fib10Fiber
=
import Micro
Micro
.
const fork: <number, never, never>(self: Micro.Micro<number, never, never>) => Micro.Micro<Micro.Handle<number, never>, never, never>

Run the `Micro` effect in a new `Handle` that can be awaited, joined, or aborted. When the parent `Micro` finishes, this `Micro` will be aborted.

fork
(
const fib: (n: number) => Micro.Micro<number>
fib
(10))
12
13
const
const program: Micro.Micro<void, never, never>
program
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<Micro.Handle<number, never>, never, never>> | YieldWrap<Micro.Micro<Micro.MicroExit<number, never>, never, never>>, void>(...args: [self: ...] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
14
const
const fiber: Micro.Handle<number, never>
fiber
= yield*
const fib10Fiber: Micro.Micro<Micro.Handle<number, never>, never, never>
fib10Fiber
15
const
const exit: Micro.MicroExit<number, never>
exit
= yield*
const fiber: Micro.Handle<number, never>
fiber
.
(property) Handle<number, never>.await: Micro.Micro<Micro.MicroExit<number, never>, never, never>
await
16
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 exit: Micro.MicroExit<number, never>
exit
)
17
})
18
19
import Micro
Micro
.
const runPromise: <void, never>(effect: Micro.Micro<void, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program: Micro.Micro<void, never, never>
program
) // { _id: 'Either', _tag: 'Right', right: 55 }

If a fiber’s result is no longer needed, it can be interrupted, which immediately terminates the fiber and safely releases all resources by running all finalizers.

Similar to .await, .interrupt returns a MicroExit value describing how the fiber completed.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const program: Micro.Micro<void, never, never>
program
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<Micro.Handle<never, never>, never, never>> | YieldWrap<Micro.Micro<Micro.MicroExit<never, never>, never, never>>, void>(...args: [self: ...] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
4
const
const fiber: Micro.Handle<never, never>
fiber
= yield*
import Micro
Micro
.
const fork: <never, never, never>(self: Micro.Micro<never, never, never>) => Micro.Micro<Micro.Handle<never, never>, never, never>

Run the `Micro` effect in a new `Handle` that can be awaited, joined, or aborted. When the parent `Micro` finishes, this `Micro` will be aborted.

fork
(
import Micro
Micro
.
const forever: <string, never, never>(self: Micro.Micro<string, never, never>) => Micro.Micro<never, never, never>

Repeat the given `Micro` effect forever, only stopping if the effect fails.

forever
(
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
("Hi!")))
5
const
const exit: Micro.MicroExit<never, never>
exit
= yield*
const fiber: Micro.Handle<never, never>
fiber
.
(property) Handle<never, never>.interrupt: Micro.Micro<Micro.MicroExit<never, never>, never, never>
interrupt
6
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 exit: Micro.MicroExit<never, never>
exit
)
7
})
8
9
import Micro
Micro
.
const runPromise: <void, never>(effect: Micro.Micro<void, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program: Micro.Micro<void, never, never>
program
)
10
/*
11
Output
12
{
13
_id: 'Either',
14
_tag: 'Left',
15
left: MicroCause.Interrupt: interrupted
16
}
17
*/

The Micro.race function lets you race multiple effects concurrently and returns the result of the first one that successfully completes.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const task1: Micro.Micro<never, string, never>
task1
=
import Micro
Micro
.
const delay: <never, string, never>(self: Micro.Micro<never, string, never>, millis: number) => Micro.Micro<never, string, never> (+1 overload)

Returns an effect that will delay the execution of this effect by the specified duration.

delay
(
import Micro
Micro
.
const fail: <string>(e: string) => Micro.Micro<never, string, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
("task1"), 1_000)
4
const
const task2: Micro.Micro<string, never, never>
task2
=
import Micro
Micro
.
const delay: <string, never, never>(self: Micro.Micro<string, never, never>, millis: number) => Micro.Micro<string, never, never> (+1 overload)

Returns an effect that will delay the execution of this effect by the specified duration.

delay
(
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
("task2"), 2_000)
5
6
const
const program: Micro.Micro<string, string, never>
program
=
import Micro
Micro
.
const race: <never, string, never, string, never, never>(self: Micro.Micro<never, string, never>, that: Micro.Micro<string, never, never>) => Micro.Micro<string, string, never> (+1 overload)

Returns an effect that races two effects, yielding the value of the first effect to succeed. Losers of the race will be interrupted immediately

race
(
const task1: Micro.Micro<never, string, never>
task1
,
const task2: Micro.Micro<string, never, never>
task2
)
7
8
import Micro
Micro
.
const runPromise: <string, string>(effect: Micro.Micro<string, string, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program: Micro.Micro<string, string, never>
program
).
(method) Promise<string>.then<void, never>(onfulfilled?: ((value: string) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
9
/*
10
Output:
11
task2
12
*/

If you need to handle the first effect to complete, whether it succeeds or fails, you can use the Micro.either function.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const task1: Micro.Micro<never, string, never>
task1
=
import Micro
Micro
.
const delay: <never, string, never>(self: Micro.Micro<never, string, never>, millis: number) => Micro.Micro<never, string, never> (+1 overload)

Returns an effect that will delay the execution of this effect by the specified duration.

delay
(
import Micro
Micro
.
const fail: <string>(e: string) => Micro.Micro<never, string, never>

Creates a `Micro` effect that will fail with the specified error. This will result in a `CauseFail`, where the error is tracked at the type level.

fail
("task1"), 1_000)
4
const
const task2: Micro.Micro<string, never, never>
task2
=
import Micro
Micro
.
const delay: <string, never, never>(self: Micro.Micro<string, never, never>, millis: number) => Micro.Micro<string, never, never> (+1 overload)

Returns an effect that will delay the execution of this effect by the specified duration.

delay
(
import Micro
Micro
.
const succeed: <string>(a: string) => Micro.Micro<string, never, never>

Creates a `Micro` effect that will succeed with the specified constant value.

succeed
("task2"), 2_000)
5
6
const
const program: Micro.Micro<Either<never, string> | Either<string, never>, never, never>
program
=
import Micro
Micro
.
const race: <Either<never, string>, never, never, Either<string, never>, never, never>(self: Micro.Micro<Either<never, string>, never, never>, that: Micro.Micro<Either<string, never>, never, never>) => Micro.Micro<...> (+1 overload)

Returns an effect that races two effects, yielding the value of the first effect to succeed. Losers of the race will be interrupted immediately

race
(
import Micro
Micro
.
const either: <never, string, never>(self: Micro.Micro<never, string, never>) => Micro.Micro<Either<never, string>, never, never>

Replace the success value of the given `Micro` effect with an `Either`, wrapping the success value in `Right` and wrapping any expected errors with a `Left`.

either
(
const task1: Micro.Micro<never, string, never>
task1
),
import Micro
Micro
.
const either: <string, never, never>(self: Micro.Micro<string, never, never>) => Micro.Micro<Either<string, never>, never, never>

Replace the success value of the given `Micro` effect with an `Either`, wrapping the success value in `Right` and wrapping any expected errors with a `Left`.

either
(
const task2: Micro.Micro<string, never, never>
task2
))
7
8
import Micro
Micro
.
const runPromise: <Either<never, string> | Either<string, never>, never>(effect: Micro.Micro<Either<never, string> | Either<string, never>, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the successful value of the computation.

runPromise
(
const program: Micro.Micro<Either<never, string> | Either<string, never>, never, never>
program
).
(method) Promise<Either<never, string> | Either<string, never>>.then<void, never>(onfulfilled?: ((value: Either<never, string> | Either<string, never>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<...>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
9
/*
10
Output:
11
{ _id: 'Either', _tag: 'Left', left: 'task1' }
12
*/

Interruptible Operation: If the operation can be interrupted, it is terminated immediately once the timeout threshold is reached, resulting in a TimeoutException.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const myEffect: Micro.Micro<string, never, never>
myEffect
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<void, never, never>>, string>(...args: [self: unknown, body: (this: unknown) => Generator<YieldWrap<Micro.Micro<void, never, never>>, string, never>] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
4
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
("Start processing...")
5
yield*
import Micro
Micro
.
const sleep: (millis: number) => Micro.Micro<void>

Create a `Micro` effect that will sleep for the specified duration.

sleep
(2_000) // Simulates a delay in processing
6
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
("Processing complete.")
7
return "Result"
8
})
9
10
const
const timedEffect: Micro.Micro<string, Micro.TimeoutException, never>
timedEffect
=
const myEffect: Micro.Micro<string, never, never>
myEffect
.
(method) Pipeable.pipe<Micro.Micro<string, never, never>, Micro.Micro<string, Micro.TimeoutException, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<string, never, never>) => Micro.Micro<string, Micro.TimeoutException, never>): Micro.Micro<...> (+21 overloads)
pipe
(
import Micro
Micro
.
const timeout: (millis: number) => <A, E, R>(self: Micro.Micro<A, E, R>) => Micro.Micro<A, E | Micro.TimeoutException, R> (+1 overload)

Returns an effect that will timeout this effect, that will fail with a `TimeoutException` if the timeout elapses before the effect has produced a value. If the timeout elapses, the running effect will be safely interrupted.

timeout
(1_000))
11
12
import Micro
Micro
.
const runPromiseExit: <string, Micro.TimeoutException>(effect: Micro.Micro<string, Micro.TimeoutException, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const timedEffect: Micro.Micro<string, Micro.TimeoutException, never>
timedEffect
).
(method) Promise<MicroExit<string, TimeoutException>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<string, Micro.TimeoutException>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<...>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
13
/*
14
Output:
15
{
16
_id: 'Either',
17
_tag: 'Left',
18
left: (MicroCause.Fail) TimeoutException
19
...stack trace...
20
}
21
*/

Uninterruptible Operation: If the operation is uninterruptible, it continues until completion before the TimeoutException is assessed.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const myEffect: Micro.Micro<string, never, never>
myEffect
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<void, never, never>>, string>(...args: [self: unknown, body: (this: unknown) => Generator<YieldWrap<Micro.Micro<void, never, never>>, string, never>] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
4
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
("Start processing...")
5
yield*
import Micro
Micro
.
const sleep: (millis: number) => Micro.Micro<void>

Create a `Micro` effect that will sleep for the specified duration.

sleep
(2_000) // Simulates a delay in processing
6
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
("Processing complete.")
7
return "Result"
8
})
9
10
const
const timedEffect: Micro.Micro<string, Micro.TimeoutException, never>
timedEffect
=
const myEffect: Micro.Micro<string, never, never>
myEffect
.
(method) Pipeable.pipe<Micro.Micro<string, never, never>, Micro.Micro<string, never, never>, Micro.Micro<string, Micro.TimeoutException, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<string, never, never>) => Micro.Micro<...>, bc: (_: Micro.Micro<...>) => Micro.Micro<...>): Micro.Micro<...> (+21 overloads)
pipe
(
11
import Micro
Micro
.
const uninterruptible: <A, E, R>(self: Micro.Micro<A, E, R>) => Micro.Micro<A, E, R>

Wrap the given `Micro` effect in an uninterruptible region, preventing the effect from being aborted.

uninterruptible
,
12
import Micro
Micro
.
const timeout: (millis: number) => <A, E, R>(self: Micro.Micro<A, E, R>) => Micro.Micro<A, E | Micro.TimeoutException, R> (+1 overload)

Returns an effect that will timeout this effect, that will fail with a `TimeoutException` if the timeout elapses before the effect has produced a value. If the timeout elapses, the running effect will be safely interrupted.

timeout
(1_000)
13
)
14
15
// Outputs a TimeoutException after the task completes, because the task is uninterruptible
16
import Micro
Micro
.
const runPromiseExit: <string, Micro.TimeoutException>(effect: Micro.Micro<string, Micro.TimeoutException, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const timedEffect: Micro.Micro<string, Micro.TimeoutException, never>
timedEffect
).
(method) Promise<MicroExit<string, TimeoutException>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<string, Micro.TimeoutException>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<...>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
17
/*
18
Output:
19
Start processing...
20
Processing complete.
21
{
22
_id: 'Either',
23
_tag: 'Left',
24
left: (MicroCause.Fail) TimeoutException
25
...stack trace...
26
}
27
*/
1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const program: Micro.Micro<void, never, never>
program
=
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<void, never, never>>, void>(...args: [self: unknown, body: (this: unknown) => Generator<YieldWrap<Micro.Micro<void, never, never>>, void, never>] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
4
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
("waiting 1 second")
5
yield*
import Micro
Micro
.
const sleep: (millis: number) => Micro.Micro<void>

Create a `Micro` effect that will sleep for the specified duration.

sleep
(1_000)
6
yield*
import Micro
Micro
.
const interrupt: Micro.Micro<never, never, never>

Abort the current `Micro` effect.

interrupt
7
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
("waiting 1 second")
8
yield*
import Micro
Micro
.
const sleep: (millis: number) => Micro.Micro<void>

Create a `Micro` effect that will sleep for the specified duration.

sleep
(1_000)
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
("done")
10
})
11
12
import Micro
Micro
.
const runPromiseExit: <void, never>(effect: Micro.Micro<void, never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const program: Micro.Micro<void, never, never>
program
).
(method) Promise<MicroExit<void, never>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<void, never>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
(
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
)
13
/*
14
Output:
15
waiting 1 second
16
{
17
_id: 'Either',
18
_tag: 'Left',
19
left: MicroCause.Interrupt: interrupted
20
}
21
*/
1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const program: Micro.Micro<void[], never, never>
program
=
import Micro
Micro
.
const forEach: <number, void, never, never>(iterable: Iterable<number>, f: (a: number, index: number) => Micro.Micro<void, never, never>, options?: { readonly concurrency?: Concurrency | undefined; readonly discard?: false | undefined; }) => Micro.Micro<...> (+1 overload)

For each element of the provided iterable, run the effect and collect the results. If the `discard` option is set to `true`, the results will be discarded and the effect will return `void`. The `concurrency` option can be set to control how many effects are run in parallel. By default, the effects are run sequentially.

forEach
(
4
[1, 2, 3],
5
(
(parameter) n: number
n
) =>
6
import Micro
Micro
.
const gen: <unknown, YieldWrap<Micro.Micro<void, never, never>>, void>(...args: [self: unknown, body: (this: unknown) => Generator<YieldWrap<Micro.Micro<void, never, never>>, void, never>] | [body: ...]) => Micro.Micro<...>
gen
(function* () {
7
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
(`start #${
(parameter) n: number
n
}`)
8
yield*
import Micro
Micro
.
const sleep: (millis: number) => Micro.Micro<void>

Create a `Micro` effect that will sleep for the specified duration.

sleep
(
(parameter) n: number
n
* 1_000)
9
if (
(parameter) n: number
n
> 1) {
10
yield*
import Micro
Micro
.
const interrupt: Micro.Micro<never, never, never>

Abort the current `Micro` effect.

interrupt
11
}
12
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
(`done #${
(parameter) n: number
n
}`)
13
}),
14
{
(property) concurrency?: Concurrency | undefined
concurrency
: "unbounded" }
15
)
16
17
import Micro
Micro
.
const runPromiseExit: <void[], never>(effect: Micro.Micro<void[], never, never>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Promise<...>

Execute the `Micro` effect and return a `Promise` that resolves with the `MicroExit` of the computation.

runPromiseExit
(
const program: Micro.Micro<void[], never, never>
program
).
(method) Promise<MicroExit<void[], never>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<void[], never>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

then
((
(parameter) exit: Micro.MicroExit<void[], never>
exit
) =>
18
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
(
var JSON: JSON

An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.

JSON
.
(method) JSON.stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string (+1 overload)

Converts a JavaScript value to a JavaScript Object Notation (JSON) string.

stringify
(
(parameter) exit: Micro.MicroExit<void[], never>
exit
, null, 2))
19
)
20
/*
21
Output:
22
start #1
23
start #2
24
start #3
25
done #1
26
{
27
"_id": "Either",
28
"_tag": "Left",
29
"left": {
30
"_tag": "Interrupt",
31
"traces": [],
32
"name": "MicroCause.Interrupt"
33
}
34
}
35
*/