Skip to content

Micro for Effect Users

The Micro module 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 { Micro } from "effect"

You can also import it using a namespace import like this:

import * as Micro from "effect/Micro"

Both forms of import allow you to access the functionalities provided by the Micro module.

However an important consideration is tree shaking, which refers to a process that eliminates unused code during the bundling of your application. Named imports may generate tree shaking issues when a bundler doesn’t support deep scope analysis.

Here are some bundlers that support deep scope analysis and thus don’t have issues with named imports:

  • Rollup
  • Webpack 5+

The Micro type uses three type parameters:

┌─── Represents the success type
│ ┌─── Represents the error type
│ │ ┌─── Represents required dependencies
▼ ▼ ▼
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 can either be successful, containing a value of type A, or it can fail, containing an error of type E wrapped in a MicroCause.

type MicroExit<A, E> = MicroExit.Success<A, E> | MicroExit.Failure<A, E>

The MicroCause type is a streamlined version of the Cause type.

Similar to how Cause is a union of types, MicroCause comes in three forms:

type MicroCause<E> = Die | Fail<E> | Interrupt
VariantDescription
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.tryMicro.tryrequires a try block
Effect.tryPromiseMicro.tryPromiserequires a try block
Effect.sleepMicro.sleeponly handles milliseconds
Effect.failCauseMicro.failWithuses MicroCause instead of Cause
Effect.failCauseSyncMicro.failWithSyncuses MicroCause instead of Cause
Micro.make
Micro.fromOption
Micro.fromEither
EffectMicro⚠️
Effect.runSyncExitMicro.runSyncExitreturns a MicroExit instead of an Exit
Effect.runPromiseExitMicro.runPromiseExitreturns a MicroExit instead of an Exit
Effect.runForkMicro.runForkreturns a MicroFiber 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.

Example (Handling Results as MicroExit)

import {
import Micro
Micro
} from "effect"
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 MicroFiber.

@since3.4.6

runSyncExit
(
import Micro
Micro
.
const succeed: <number>(value: number) => Micro.Micro<number, never, never>

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

@since3.4.0

succeed
(1))
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 and process.stderr. 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 for more information.

Example using the global console:

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:

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

@seesource

console
.
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) (the arguments are all passed to util.format()).

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() for more information.

@sincev0.1.100

log
(
const result1: Micro.MicroExit<number, never>
result1
)
/*
Output:
{
"_id": "MicroExit",
"_tag": "Success",
"value": 1
}
*/
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 MicroFiber.

@since3.4.6

runSyncExit
(
import Micro
Micro
.
const fail: <string>(error: string) => Micro.Micro<never, string, never>

Creates a Micro effect that fails with the given error.

This results in a Fail variant of the MicroCause type, where the error is tracked at the type level.

@since3.4.0

fail
("my error"))
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 and process.stderr. 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 for more information.

Example using the global console:

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:

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

@seesource

console
.
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) (the arguments are all passed to util.format()).

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() for more information.

@sincev0.1.100

log
(
const result2: Micro.MicroExit<never, string>
result2
)
/*
Output:
{
"_id": "MicroExit",
"_tag": "Failure",
"cause": {
"_tag": "Fail",
"traces": [],
"name": "MicroCause.Fail",
"error": "my error"
}
}
*/

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

Example (Handling Results as MicroExit)

import {
import Micro
Micro
} from "effect"
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.

@since3.4.6

runPromiseExit
(
import Micro
Micro
.
const succeed: <number>(value: number) => Micro.Micro<number, never, never>

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

@since3.4.0

succeed
(1)).
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.

@paramonfulfilled The callback to execute when the Promise is resolved.

@paramonrejected The callback to execute when the Promise is rejected.

@returnsA Promise for the completion of which ever callback is executed.

then
(
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 and process.stderr. 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 for more information.

Example using the global console:

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:

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

@seesource

console
.
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) (the arguments are all passed to util.format()).

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() for more information.

@sincev0.1.100

log
)
/*
Output:
{
"_id": "MicroExit",
"_tag": "Success",
"value": 1
}
*/
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.

@since3.4.6

runPromiseExit
(
import Micro
Micro
.
const fail: <string>(error: string) => Micro.Micro<never, string, never>

Creates a Micro effect that fails with the given error.

This results in a Fail variant of the MicroCause type, where the error is tracked at the type level.

@since3.4.0

fail
("my error")).
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.

@paramonfulfilled The callback to execute when the Promise is resolved.

@paramonrejected The callback to execute when the Promise is rejected.

@returnsA Promise for the completion of which ever callback is executed.

then
(
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 and process.stderr. 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 for more information.

Example using the global console:

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:

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

@seesource

console
.
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) (the arguments are all passed to util.format()).

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() for more information.

@sincev0.1.100

log
)
/*
Output:
{
"_id": "MicroExit",
"_tag": "Failure",
"cause": {
"_tag": "Fail",
"traces": [],
"name": "MicroCause.Fail",
"error": "my error"
}
}
*/

The Micro.runFork function executes the effect and return a MicroFiber that can be awaited, joined, or aborted.

You can listen for the result by adding an observer using the addObserver method.

Example (Observing an Asynchronous Effect)

import {
import Micro
Micro
} from "effect"
// ┌─── MicroFiber<number, never>
// ▼
const
const fiber: MicroFiberImpl<number, never>
fiber
=
import Micro
Micro
.
const succeed: <number>(value: number) => Micro.Micro<number, never, never>

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

@since3.4.0

succeed
(42).
Pipeable.pipe<Micro.Micro<number, never, never>, Micro.Micro<number, never, never>, MicroFiberImpl<number, never>>(this: Micro.Micro<...>, ab: (_: Micro.Micro<number, never, never>) => Micro.Micro<...>, bc: (_: Micro.Micro<...>) => MicroFiberImpl<...>): MicroFiberImpl<...> (+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.

@since3.4.0

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) => MicroFiberImpl<...>

Execute the Micro effect and return a MicroFiber that can be awaited, joined, or aborted.

You can listen for the result by adding an observer using the handle's addObserver method.

@example

import * as Micro from "effect/Micro"
const handle = Micro.succeed(42).pipe(
Micro.delay(1000),
Micro.runFork
)
handle.addObserver((exit) => {
console.log(exit)
})

@since3.4.0

runFork
)
// Attach an observer to log the result when the effect completes
const fiber: MicroFiberImpl<number, never>
fiber
.
MicroFiberImpl<number, never>.addObserver(cb: (exit: Micro.MicroExit<number, never>) => void): () => void
addObserver
((
result: Micro.MicroExit<number, never>
result
) => {
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 and process.stderr. 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 for more information.

Example using the global console:

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:

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

@seesource

console
.
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) (the arguments are all passed to util.format()).

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() for more information.

@sincev0.1.100

log
(
result: Micro.MicroExit<number, never>
result
)
})
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 and process.stderr. 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 for more information.

Example using the global console:

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:

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

@seesource

console
.
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) (the arguments are all passed to util.format()).

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() for more information.

@sincev0.1.100

log
("observing...")
/*
Output:
observing...
{
"_id": "MicroExit",
"_tag": "Success",
"value": 42
}
*/
EffectMicro⚠️
Effect.andThenMicro.andThendoesn’t handle Promise or () => Promise as argument
Effect.tapMicro.tapdoesn’t handle () => Promise as argument
Effect.allMicro.allno batching and mode options
Effect.forEachMicro.forEachno batching option
Effect.filterMicro.filterno batching option
Effect.filterMapMicro.filterMapthe filter is effectful
EffectMicro⚠️
Effect.exitMicro.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:

Example (Accessing a Service in Micro.gen)

import {
import Micro
Micro
,
import Context

@since2.0.0

@since2.0.0

Context
} from "effect"
class
class Random
Random
extends
import Context

@since2.0.0

@since2.0.0

Context
.
const Tag: <"MyRandomService">(id: "MyRandomService") => <Self, Shape>() => Context.TagClass<Self, "MyRandomService", Shape>

@example

import { Context, Layer } from "effect"
class MyTag extends Context.Tag("MyTag")<
MyTag,
{ readonly myNum: number }
>() {
static Live = Layer.succeed(this, { myNum: 108 })
}

@since2.0.0

Tag
("MyRandomService")<
class Random
Random
,
{ readonly
next: Micro.Micro<number, never, never>
next
:
import Micro
Micro
.
interface Micro<out A, out E = never, out R = never>

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

@since3.4.0

@since3.4.0

Micro
<number> }
>() {}
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<...>

@since3.4.0

gen
(function* () {
// const random = yield* Random // this doesn't work
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> (+1 overload)

Access the given Context.Tag from the environment.

@since3.4.0

service
(
class Random
Random
)
const
const randomNumber: number
randomNumber
= yield*
const random: {
readonly next: Micro.Micro<number>;
}
random
.
next: Micro.Micro<number, never, never>
next
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 and process.stderr. 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 for more information.

Example using the global console:

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:

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

@seesource

console
.
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) (the arguments are all passed to util.format()).

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() for more information.

@sincev0.1.100

log
(`random number: ${
const randomNumber: number
randomNumber
}`)
})
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<number, never, never>;
}>, service: {
next: Micro.Micro<number, never, never>;
}) => Micro.Micro<...> (+1 overload)

Add the provided service to the current context.

@since3.4.0

provideService
(
const program: Micro.Micro<void, never, Random>
program
,
class Random
Random
, {
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 succeeds with a lazily evaluated value.

If the evaluation of the value throws an error, the effect will fail with a Die variant of the MicroCause type.

@since3.4.0

sync
(() =>
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.random(): number

Returns a pseudorandom number between 0 and 1.

random
())
})
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.

@since3.4.0

runPromise
(
const runnable: Micro.Micro<void, never, never>
runnable
)
/*
Example Output:
random number: 0.8241872233134417
*/
EffectMicro⚠️
ScopeMicroScopereturns a MicroScope instead of a Scope
Scope.makeMicro.scopeMakereturns a MicroScope instead of a Scope
EffectMicro⚠️
Effect.retryMicro.retrydifferent options
EffectMicro⚠️
Effect.repeatMicro.repeatdifferent options
Micro.repeatExit
EffectMicro
Micro.timeoutOrElse
EffectMicro⚠️
Effect.sandboxMicro.sandboxreturns a MicroCause<E> instead of Cause<E>
EffectMicro⚠️
Micro.filterOrFailWith
Effect.tapErrorCauseMicro.tapErrorCauseMicroCause<E> instead of Cause<E>
Micro.tapCauseIf
Effect.tapDefectMicro.tapDefectunknown instead of Cause<never>
EffectMicro⚠️
Effect.provideMicro.provideContextonly handles Context
Micro.provideScope
Micro.service
EffectMicro⚠️
Effect.addFinalizerMicro.addFinalizerMicroExit instead of Exit and no R
Effect.acquireReleaseMicro.acquireReleaseMicroExit instead of Exit
Effect.acquireUseReleaseMicro.acquireUseReleaseMicroExit instead of Exit
Effect.onExitMicro.onExitMicroExit instead of Exit
Effect.onErrorMicro.onErroruses MicroCause instead of Cause
Micro.onExitIf
EffectMicro⚠️
Effect.forkMicro.forkMicroFiber instead of RuntimeFiber
Effect.forkDaemonMicro.forkDaemonMicroFiber instead of RuntimeFiber
Effect.forkInMicro.forkInMicroFiber instead of RuntimeFiber
Effect.forkScopedMicro.forkScopedMicroFiber instead of RuntimeFiber