Skip to content

Micro for Effect Users

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.

Micro is a part of the Effect library and can be imported just like any other module:

import * as Micro from "effect/Micro"

The Micro type uses three type parameters:

Micro<Success, Error, Requirements>

which mirror those of the Effect type.

The MicroExit type is a streamlined version of the Exit type, 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 is a streamlined version of the Cause type.

Similar to how Cause is a union of types, 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.

The MicroSchedule type is a streamlined version of the Schedule type.

type MicroSchedule = (attempt: number, elapsed: number) => Option<number>

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.

Below, you’ll find a series of comparisons between the functionalities of Effect and Micro. Each table lists a functionality of Effect alongside its counterpart in Micro. The icons used have the following meanings:

  • ⚠️: The feature is available in Micro, but with some differences from Effect.
  • ❌: The feature is not available in Effect.
EffectMicro
Effect.try⚠️ Micro.tryrequires a try block
Effect.tryPromise⚠️ Micro.tryPromiserequires a try block
Effect.sleep⚠️ Micro.sleeponly handles milliseconds
Effect.failCause⚠️ Micro.failWithuses MicroCause instead of Cause
Effect.failCauseSync⚠️ Micro.failWithSyncuses MicroCause instead of Cause
Micro.make
Micro.fromOption
Micro.fromEither
EffectMicro
Effect.runSyncExit⚠️ Micro.runSyncExitreturns a MicroExit instead of an Exit
Effect.runPromiseExit⚠️ Micro.runPromiseExitreturns a MicroExit instead of an Exit
Effect.runFork⚠️ Micro.runForkreturns a Handle instead of a RuntimeFiber

The Micro.runSyncExit function is used to execute an Effect synchronously, which means it runs immediately and returns the result as a MicroExit.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const result1: Micro.MicroExit<number, never>
result1
=
import Micro
Micro
.
const runSyncExit: <number, never>(effect: Micro.Micro<number, never, never>) => Micro.MicroExit<number, never>

Attempt to execute the `Micro` effect synchronously and return the `MicroExit`. If any asynchronous effects are encountered, the function will return a `CauseDie` containing the `Handle`.

runSyncExit
(
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
(1))
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
(
const result1: Micro.MicroExit<number, never>
result1
)
5
/*
6
Output:
7
{ _id: 'Either', _tag: 'Right', right: 1 }
8
*/
9
10
const
const result2: Micro.MicroExit<never, string>
result2
=
import Micro
Micro
.
const runSyncExit: <never, string>(effect: Micro.Micro<never, string, never>) => Micro.MicroExit<never, string>

Attempt to execute the `Micro` effect synchronously and return the `MicroExit`. If any asynchronous effects are encountered, the function will return a `CauseDie` containing the `Handle`.

runSyncExit
(
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
("my error"))
11
namespace console var console: Console

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

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

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

log
(
const result2: Micro.MicroExit<never, string>
result2
)
12
/*
13
Output:
14
{ _id: 'Either', _tag: 'Left', left: MicroCause.Fail: my error }
15
*/

The Micro.runPromiseExit function is used to execute an Effect and obtain the result as a Promise that resolves to a MicroExit.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
import Micro
Micro
.
const runPromiseExit: <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 `MicroExit` of the computation.

runPromiseExit
(
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
(1)).
(method) Promise<MicroExit<number, never>>.then<void, never>(onfulfilled?: ((value: Micro.MicroExit<number, 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
)
4
/*
5
Output:
6
{ _id: 'Either', _tag: 'Right', right: 1 }
7
*/
8
9
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
(
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
("my error")).
(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
)
10
/*
11
Output:
12
{ _id: 'Either', _tag: 'Left', left: MicroCause.Fail: my error }
13
*/

The Micro.runFork function executes the 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.

1
import * as
import Micro
Micro
from "effect/Micro"
2
3
const
const handle: Micro.Handle<number, never>
handle
=
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).
(method) Pipeable.pipe<Micro.Micro<number, never, never>, Micro.Micro<number, never, never>, Micro.Handle<number, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<number, never, never>) => Micro.Micro<...>, bc: (_: Micro.Micro<...>) => Micro.Handle<...>): Micro.Handle<...> (+21 overloads)
pipe
(
import Micro
Micro
.
const delay: (millis: number) => <A, E, R>(self: Micro.Micro<A, E, R>) => Micro.Micro<A, E, R> (+1 overload)

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

delay
(1000),
import Micro
Micro
.
const runFork: <A, E>(effect: Micro.Micro<A, E>, options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: Micro.MicroScheduler | undefined; } | undefined) => Micro.Handle<A, E>

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
)
4
5
const handle: Micro.Handle<number, never>
handle
.
(property) Handle<number, never>.addObserver: (observer: (exit: Micro.MicroExit<number, never>) => void) => void
addObserver
((
(parameter) result: Micro.MicroExit<number, never>
result
) => {
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
(
(parameter) result: Micro.MicroExit<number, never>
result
)
7
})
8
namespace console var console: Console

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

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

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

log
("observing...")
9
/*
10
Output:
11
observing...
12
{ _id: 'Either', _tag: 'Right', right: 42 }
13
*/
EffectMicro
Effect.andThen⚠️ Micro.andThendoesn’t handle Promise or () => Promise as argument
Effect.tap⚠️ Micro.tapdoesn’t handle () => Promise as argument
Effect.all⚠️ Micro.allno batching and mode options
Effect.forEach⚠️ Micro.forEachno batching option
Effect.filter⚠️ Micro.filterno batching option
Effect.filterMap⚠️ Micro.filterMapeffectful
EffectMicro
Effect.exit⚠️ Micro.exitreturns a MicroExit instead of an Exit
EffectMicro
Micro.catchCauseIf
EffectMicro
Micro.timeoutOrElse

To access a service while using Micro.gen, you need to wrap the service tag using the Micro.service function:

1
import * as
import Context
Context
from "effect/Context"
2
import * as
import Micro
Micro
from "effect/Micro"
3
4
class
class Random
Random
extends
import Context
Context
.
const Tag: <"MyRandomService">(id: "MyRandomService") => <Self, Shape>() => Context.TagClass<Self, "MyRandomService", Shape> namespace Tag
Tag
("MyRandomService")<
5
class Random
Random
,
6
{ 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> }
7
>() {}
8
9
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* () {
10
// const random = yield* Random // this doesn't work
11
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
)
12
const
const randomNumber: number
randomNumber
= yield*
const random: { readonly next: Micro.Micro<number>; }
random
.
(property) next: Micro.Micro<number, never, never>
next
13
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
}`)
14
})
15
16
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
, {
17
(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
())
18
})
19
20
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
)
21
/*
22
Example Output:
23
random number: 0.8241872233134417
24
*/
EffectMicro
Scope⚠️ MicroScopereturns a MicroScope instead of a Scope
Scope.make⚠️ Micro.scopeMakereturns a MicroScope instead of a Scope
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
*/
EffectMicro
Effect.retry⚠️ Micro.retrydifferent options
EffectMicro
Effect.repeat⚠️ Micro.repeatdifferent options
❌ (Effect.exit + Effect.repeat)⚠️ Micro.repeatExit
EffectMicro
Micro.timeoutOrElse
EffectMicro
Effect.sandbox⚠️ Micro.sandboxMicroCause<E> instead of Cause<E>
EffectMicro
Micro.filterOrFailWith
Effect.tapErrorCause⚠️ Micro.tapErrorCauseMicroCause<E> instead of Cause<E>
Micro.tapCauseIf
Effect.tapDefect⚠️ Micro.tapDefectunknown instead of Cause<never>
EffectMicro
Effect.provide⚠️ Micro.provideContextonly handles Context
Micro.provideScope
Micro.service
EffectMicro
Effect.addFinalizer⚠️ Micro.addFinalizerMicroExit instead of Exit and no R
Effect.acquireRelease⚠️ Micro.acquireReleaseMicroExit instead of Exit
Effect.acquireUseRelease⚠️ Micro.acquireUseReleaseMicroExit instead of Exit
Effect.onExit⚠️ Micro.onExitMicroExit instead of Exit
Effect.onError⚠️ Micro.onErroruses MicroCause instead of Cause
Micro.onExitIf
EffectMicro
Effect.fork⚠️ Micro.forkHandle instead of RuntimeFiber
Effect.forkDaemon⚠️ Micro.forkDaemonHandle instead of RuntimeFiber
Effect.forkIn⚠️ Micro.forkInHandle instead of RuntimeFiber
Effect.forkScoped⚠️ Micro.forkScopedHandle instead of RuntimeFiber