Micro.ts overview
A lightweight alternative to the Effect
data type, with a subset of the functionality.
Since v3.4.0
Exports Grouped by Category
- MicroCause
- MicroExit
- MicroFiber
- collecting & elements
- constructors
- delays & timeouts
- do notation
- environment
- environment refs
- error handling
- errors
- execution
- fiber & forking
- filtering & conditionals
- flags
- guards
- interruption
- mapping & sequencing
- models
- pattern matching
- references
- repetition
- resources & finalization
- scheduler
- scheduling
- sequencing
- type ids
- type lambdas
- utils
- zipping
MicroCause
MicroCause (type alias)
A MicroCause
is a data type that represents the different ways a Micro
can fail.
Details
MicroCause
comes in three forms:
Die
: Indicates an unforeseen defect that wasn’t planned for in the system’s logic.Fail
: Covers anticipated errors that are recognized and typically handled within the application.Interrupt
: Signifies an operation that has been purposefully stopped.
Signature
type MicroCause<E> = MicroCause.Die | MicroCause.Fail<E> | MicroCause.Interrupt
Since v3.4.6
MicroCause (namespace)
Since v3.4.6
Proto (interface)
Signature
export interface Proto<Tag extends string, E> extends Pipeable, globalThis.Error {
readonly [MicroCauseTypeId]: {
_E: Covariant<E>
}
readonly _tag: Tag
readonly traces: ReadonlyArray<string>
}
Since v3.4.0
Die (interface)
Signature
export interface Die extends Proto<"Die", never> {
readonly defect: unknown
}
Since v3.4.6
Fail (interface)
Signature
export interface Fail<E> extends Proto<"Fail", E> {
readonly error: E
}
Since v3.4.6
Interrupt (interface)
Signature
export interface Interrupt extends Proto<"Interrupt", never> {}
Since v3.4.6
Error (type alias)
Signature
type Error<T> = T extends MicroCause.Fail<infer E> ? E : never
Since v3.4.6
MicroCauseTypeId
Signature
declare const MicroCauseTypeId: unique symbol
Since v3.4.6
MicroCauseTypeId (type alias)
Signature
type MicroCauseTypeId = typeof MicroCauseTypeId
Since v3.4.6
causeDie
Signature
declare const causeDie: (defect: unknown, traces?: ReadonlyArray<string>) => MicroCause<never>
Since v3.4.6
causeFail
Signature
declare const causeFail: <E>(error: E, traces?: ReadonlyArray<string>) => MicroCause<E>
Since v3.4.6
causeInterrupt
Signature
declare const causeInterrupt: (traces?: ReadonlyArray<string>) => MicroCause<never>
Since v3.4.6
causeIsDie
Signature
declare const causeIsDie: <E>(self: MicroCause<E>) => self is MicroCause.Die
Since v3.4.6
causeIsFail
Signature
declare const causeIsFail: <E>(self: MicroCause<E>) => self is MicroCause.Fail<E>
Since v3.4.6
causeIsInterrupt
Signature
declare const causeIsInterrupt: <E>(self: MicroCause<E>) => self is MicroCause.Interrupt
Since v3.4.6
causeSquash
Signature
declare const causeSquash: <E>(self: MicroCause<E>) => unknown
Since v3.4.6
causeWithTrace
Signature
declare const causeWithTrace: {
(trace: string): <E>(self: MicroCause<E>) => MicroCause<E>
<E>(self: MicroCause<E>, trace: string): MicroCause<E>
}
Since v3.4.6
MicroExit
MicroExit (type alias)
The MicroExit
type is used to represent the result 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
.
Signature
type MicroExit<A, E> = MicroExit.Success<A, E> | MicroExit.Failure<A, E>
Since v3.4.6
MicroExit (namespace)
Since v3.4.6
Proto (interface)
Signature
export interface Proto<out A, out E = never> extends Micro<A, E> {
readonly [MicroExitTypeId]: MicroExitTypeId
}
Since v3.4.6
Success (interface)
Signature
export interface Success<out A, out E> extends Proto<A, E> {
readonly _tag: "Success"
readonly value: A
}
Since v3.4.6
Failure (interface)
Signature
export interface Failure<out A, out E> extends Proto<A, E> {
readonly _tag: "Failure"
readonly cause: MicroCause<E>
}
Since v3.4.6
MicroExitTypeId
Signature
declare const MicroExitTypeId: unique symbol
Since v3.4.0
MicroExitTypeId (type alias)
Signature
type MicroExitTypeId = typeof TypeId
Since v3.4.0
exitDie
Signature
declare const exitDie: (defect: unknown) => MicroExit<never>
Since v3.4.6
exitFail
Signature
declare const exitFail: <E>(e: E) => MicroExit<never, E>
Since v3.4.6
exitFailCause
Signature
declare const exitFailCause: <E>(cause: MicroCause<E>) => MicroExit<never, E>
Since v3.4.6
exitInterrupt
Signature
declare const exitInterrupt: MicroExit<never, never>
Since v3.4.6
exitIsDie
Signature
declare const exitIsDie: <A, E>(
self: MicroExit<A, E>
) => self is MicroExit.Failure<A, E> & { readonly cause: MicroCause.Die }
Since v3.4.6
exitIsFail
Signature
declare const exitIsFail: <A, E>(
self: MicroExit<A, E>
) => self is MicroExit.Failure<A, E> & { readonly cause: MicroCause.Fail<E> }
Since v3.4.6
exitIsFailure
Signature
declare const exitIsFailure: <A, E>(self: MicroExit<A, E>) => self is MicroExit.Failure<A, E>
Since v3.4.6
exitIsInterrupt
Signature
declare const exitIsInterrupt: <A, E>(
self: MicroExit<A, E>
) => self is MicroExit.Failure<A, E> & { readonly cause: MicroCause.Interrupt }
Since v3.4.6
exitIsSuccess
Signature
declare const exitIsSuccess: <A, E>(self: MicroExit<A, E>) => self is MicroExit.Success<A, E>
Since v3.4.6
exitSucceed
Signature
declare const exitSucceed: <A>(a: A) => MicroExit<A, never>
Since v3.4.6
exitVoid
Signature
declare const exitVoid: MicroExit<void, never>
Since v3.4.6
exitVoidAll
Signature
declare const exitVoidAll: <I extends Iterable<MicroExit<any, any>>>(
exits: I
) => MicroExit<void, I extends Iterable<MicroExit<infer _A, infer _E>> ? _E : never>
Since v3.11.0
isMicroExit
Signature
declare const isMicroExit: (u: unknown) => u is MicroExit<unknown, unknown>
Since v3.4.6
MicroFiber
MicroFiber (interface)
Signature
export interface MicroFiber<out A, out E = never> {
readonly [MicroFiberTypeId]: MicroFiber.Variance<A, E>
readonly currentOpCount: number
readonly getRef: <I, A>(ref: Context.Reference<I, A>) => A
readonly context: Context.Context<never>
readonly addObserver: (cb: (exit: MicroExit<A, E>) => void) => () => void
readonly unsafeInterrupt: () => void
readonly unsafePoll: () => MicroExit<A, E> | undefined
}
Since v3.11.0
MicroFiber (namespace)
Since v3.11.0
Variance (interface)
Signature
export interface Variance<out A, out E = never> {
readonly _A: Covariant<A>
readonly _E: Covariant<E>
}
Since v3.11.0
MicroFiberTypeId
Signature
declare const MicroFiberTypeId: unique symbol
Since v3.11.0
MicroFiberTypeId (type alias)
Signature
type MicroFiberTypeId = typeof MicroFiberTypeId
Since v3.11.0
fiberAwait
Signature
declare const fiberAwait: <A, E>(self: MicroFiber<A, E>) => Micro<MicroExit<A, E>>
Since v3.11.0
fiberInterrupt
Signature
declare const fiberInterrupt: <A, E>(self: MicroFiber<A, E>) => Micro<void>
Since v3.11.0
fiberInterruptAll
Signature
declare const fiberInterruptAll: <A extends Iterable<MicroFiber<any, any>>>(fibers: A) => Micro<void>
Since v3.11.0
fiberJoin
Signature
declare const fiberJoin: <A, E>(self: MicroFiber<A, E>) => Micro<A, E>
Since v3.11.2
collecting & elements
all
Runs all the provided effects in sequence respecting the structure provided in input.
Supports multiple arguments, a single argument tuple / array or record / struct.
Signature
declare const all: <
const Arg extends Iterable<Micro<any, any, any>> | Record<string, Micro<any, any, any>>,
O extends NoExcessProperties<
{ readonly concurrency?: Concurrency | undefined; readonly discard?: boolean | undefined },
O
>
>(
arg: Arg,
options?: O
) => All.Return<Arg, O>
Since v3.4.0
filter
Effectfully filter the elements of the provided iterable.
Use the concurrency
option to control how many elements are processed concurrently.
Signature
declare const filter: <A, E, R>(
iterable: Iterable<A>,
f: (a: NoInfer<A>) => Micro<boolean, E, R>,
options?: { readonly concurrency?: Concurrency | undefined; readonly negate?: boolean | undefined }
) => Micro<Array<A>, E, R>
Since v3.4.0
filterMap
Effectfully filter the elements of the provided iterable.
Use the concurrency
option to control how many elements are processed concurrently.
Signature
declare const filterMap: <A, B, E, R>(
iterable: Iterable<A>,
f: (a: NoInfer<A>) => Micro<Option.Option<B>, E, R>,
options?: { readonly concurrency?: Concurrency | undefined }
) => Micro<Array<B>, E, R>
Since v3.4.0
forEach
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 concurrently. By default, the effects are run sequentially.
Signature
declare const forEach: {
<A, B, E, R>(
iterable: Iterable<A>,
f: (a: A, index: number) => Micro<B, E, R>,
options?: { readonly concurrency?: Concurrency | undefined; readonly discard?: false | undefined }
): Micro<Array<B>, E, R>
<A, B, E, R>(
iterable: Iterable<A>,
f: (a: A, index: number) => Micro<B, E, R>,
options: { readonly concurrency?: Concurrency | undefined; readonly discard: true }
): Micro<void, E, R>
}
Since v3.4.0
whileLoop
Signature
declare const whileLoop: <A, E, R>(options: {
readonly while: LazyArg<boolean>
readonly body: LazyArg<Micro<A, E, R>>
readonly step: (a: A) => void
}) => Micro<void, E, R>
Since v3.11.0
constructors
async
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.
Signature
declare const async: <A, E = never, R = never>(
register: (resume: (effect: Micro<A, E, R>) => void, signal: AbortSignal) => void | Micro<void, never, R>
) => Micro<A, E, R>
Since v3.4.0
die
Creates a Micro
effect that will die with the specified error.
This results in a Die
variant of the MicroCause
type, where the error is not tracked at the type level.
Signature
declare const die: (defect: unknown) => Micro<never>
Since v3.4.0
fail
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.
Signature
declare const fail: <E>(error: E) => Micro<never, E>
Since v3.4.0
failCause
Creates a Micro
effect that will fail with the specified MicroCause
.
Signature
declare const failCause: <E>(cause: MicroCause<E>) => Micro<never, E>
Since v3.4.6
failCauseSync
Creates a Micro
effect that will fail with the lazily evaluated MicroCause
.
Signature
declare const failCauseSync: <E>(evaluate: LazyArg<MicroCause<E>>) => Micro<never, E>
Since v3.4.0
failSync
Creates a Micro
effect that will fail with the lazily evaluated error.
This results in a Fail
variant of the MicroCause
type, where the error is tracked at the type level.
Signature
declare const failSync: <E>(error: LazyArg<E>) => Micro<never, E>
Since v3.4.6
fromEither
Converts an Either
into a Micro
effect, that will fail with the left side of the either if it is a Left
. Otherwise, it will succeed with the right side of the either.
Signature
declare const fromEither: <R, L>(either: Either.Either<R, L>) => Micro<R, L>
Since v3.4.0
fromOption
Converts an Option
into a Micro
effect, that will fail with NoSuchElementException
if the option is None
. Otherwise, it will succeed with the value of the option.
Signature
declare const fromOption: <A>(option: Option.Option<A>) => Micro<A, NoSuchElementException>
Since v3.4.0
gen
Signature
declare const gen: <Self, Eff extends YieldWrap<Micro<any, any, any>>, AEff>(
...args: [self: Self, body: (this: Self) => Generator<Eff, AEff, never>] | [body: () => Generator<Eff, AEff, never>]
) => Micro<
AEff,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Micro<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Micro<infer _A, infer _E, infer R>>] ? R : never
>
Since v3.4.0
never
A Micro
that will never succeed or fail. It wraps setInterval
to prevent the Javascript runtime from exiting.
Signature
declare const never: Micro<never, never, never>
Since v3.4.0
promise
Wrap a Promise
into a Micro
effect.
Any errors will result in a Die
variant of the MicroCause
type, where the error is not tracked at the type level.
Signature
declare const promise: <A>(evaluate: (signal: AbortSignal) => PromiseLike<A>) => Micro<A>
Since v3.4.0
succeed
Creates a Micro
effect that will succeed with the specified constant value.
Signature
declare const succeed: <A>(value: A) => Micro<A>
Since v3.4.0
succeedNone
Creates a Micro
effect that succeeds with None
.
Signature
declare const succeedNone: Micro<Option.Option<never>, never, never>
Since v3.4.0
succeedSome
Creates a Micro
effect that will succeed with the value wrapped in Some
.
Signature
declare const succeedSome: <A>(a: A) => Micro<Option.Option<A>>
Since v3.4.0
suspend
Lazily creates a Micro
effect from the given side-effect.
Signature
declare const suspend: <A, E, R>(evaluate: LazyArg<Micro<A, E, R>>) => Micro<A, E, R>
Since v3.4.0
sync
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.
Signature
declare const sync: <A>(evaluate: LazyArg<A>) => Micro<A>
Since v3.4.0
try
The Micro
equivalent of a try / catch block, which allows you to map thrown errors to a specific error type.
Example
import { Micro } from "effect"
Micro.try({
try: () => {
throw new Error("boom")
},
catch: (cause) => new Error("caught", { cause })
})
Signature
declare const try: <A, E>(options: { try: LazyArg<A>; catch: (error: unknown) => E; }) => Micro<A, E>
Since v3.4.0
tryPromise
Wrap a Promise
into a Micro
effect. Any errors will be caught and converted into a specific error type.
Example
import { Micro } from "effect"
Micro.tryPromise({
try: () => Promise.resolve("success"),
catch: (cause) => new Error("caught", { cause })
})
Signature
declare const tryPromise: <A, E>(options: {
readonly try: (signal: AbortSignal) => PromiseLike<A>
readonly catch: (error: unknown) => E
}) => Micro<A, E>
Since v3.4.0
void
A Micro
effect that will succeed with void
(undefined
).
Signature
declare const void: Micro<void, never, never>
Since v3.4.0
withMicroFiber
Create a Micro
effect using the current MicroFiber
.
Signature
declare const withMicroFiber: <A, E = never, R = never>(
evaluate: (fiber: MicroFiberImpl<A, E>) => Micro<A, E, R>
) => Micro<A, E, R>
Since v3.4.0
yieldFlush
Flush any yielded effects that are waiting to be executed.
Signature
declare const yieldFlush: Micro<void, never, never>
Since v3.4.0
yieldNow
Pause the execution of the current Micro
effect, and resume it on the next scheduler tick.
Signature
declare const yieldNow: Micro<void, never, never>
Since v3.4.0
yieldNowWith
Pause the execution of the current Micro
effect, and resume it on the next scheduler tick.
Signature
declare const yieldNowWith: (priority?: number) => Micro<void>
Since v3.4.0
delays & timeouts
delay
Returns an effect that will delay the execution of this effect by the specified duration.
Signature
declare const delay: {
(millis: number): <A, E, R>(self: Micro<A, E, R>) => Micro<A, E, R>
<A, E, R>(self: Micro<A, E, R>, millis: number): Micro<A, E, R>
}
Since v3.4.0
sleep
Create a Micro
effect that will sleep for the specified duration.
Signature
declare const sleep: (millis: number) => Micro<void>
Since v3.4.0
timeout
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.
Signature
declare const timeout: {
(millis: number): <A, E, R>(self: Micro<A, E, R>) => Micro<A, E | TimeoutException, R>
<A, E, R>(self: Micro<A, E, R>, millis: number): Micro<A, E | TimeoutException, R>
}
Since v3.4.0
timeoutOption
Returns an effect that will timeout this effect, succeeding with a None
if the timeout elapses before the effect has produced a value; and Some
of the produced value otherwise.
If the timeout elapses, the running effect will be safely interrupted.
Signature
declare const timeoutOption: {
(millis: number): <A, E, R>(self: Micro<A, E, R>) => Micro<Option.Option<A>, E, R>
<A, E, R>(self: Micro<A, E, R>, millis: number): Micro<Option.Option<A>, E, R>
}
Since v3.4.0
timeoutOrElse
Returns an effect that will timeout this effect, that will execute the fallback effect if the timeout elapses before the effect has produced a value.
If the timeout elapses, the running effect will be safely interrupted.
Signature
declare const timeoutOrElse: {
<A2, E2, R2>(options: {
readonly duration: number
readonly onTimeout: LazyArg<Micro<A2, E2, R2>>
}): <A, E, R>(self: Micro<A, E, R>) => Micro<A | A2, E | E2, R | R2>
<A, E, R, A2, E2, R2>(
self: Micro<A, E, R>,
options: { readonly duration: number; readonly onTimeout: LazyArg<Micro<A2, E2, R2>> }
): Micro<A | A2, E | E2, R | R2>
}
Since v3.4.0
do notation
Do
Start a do notation block.
Signature
declare const Do: Micro<{}, never, never>
Since v3.4.0
bind
Bind the success value of this Micro
effect to the provided name.
Signature
declare const bind: {
<N extends string, A extends Record<string, any>, B, E2, R2>(
name: N,
f: (a: NoInfer<A>) => Micro<B, E2, R2>
): <E, R>(self: Micro<A, E, R>) => Micro<Simplify<Omit<A, N> & { [K in N]: B }>, E | E2, R | R2>
<A extends Record<string, any>, E, R, B, E2, R2, N extends string>(
self: Micro<A, E, R>,
name: N,
f: (a: NoInfer<A>) => Micro<B, E2, R2>
): Micro<Simplify<Omit<A, N> & { [K in N]: B }>, E | E2, R | R2>
}
Since v3.4.0
bindTo
Bind the success value of this Micro
effect to the provided name.
Signature
declare const bindTo: {
<N extends string>(name: N): <A, E, R>(self: Micro<A, E, R>) => Micro<{ [K in N]: A }, E, R>
<A, E, R, N extends string>(self: Micro<A, E, R>, name: N): Micro<{ [K in N]: A }, E, R>
}
Since v3.4.0
let
Bind the result of a synchronous computation to the given name.
Signature
declare const let: {
<N extends string, A extends Record<string, any>, B>(
name: N,
f: (a: NoInfer<A>) => B
): <E, R>(self: Micro<A, E, R>) => Micro<Simplify<Omit<A, N> & { [K in N]: B }>, E, R>
<A extends Record<string, any>, E, R, B, N extends string>(
self: Micro<A, E, R>,
name: N,
f: (a: NoInfer<A>) => B
): Micro<Simplify<Omit<A, N> & { [K in N]: B }>, E, R>
}
Since v3.4.0
environment
context
Access the current Context
from the environment.
Signature
declare const context: <R>() => Micro<Context.Context<R>>
Since v3.4.0
provideContext
Merge the given Context
with the current context.
Signature
declare const provideContext: {
<XR>(context: Context.Context<XR>): <A, E, R>(self: Micro<A, E, R>) => Micro<A, E, Exclude<R, XR>>
<A, E, R, XR>(self: Micro<A, E, R>, context: Context.Context<XR>): Micro<A, E, Exclude<R, XR>>
}
Since v3.4.0
provideService
Add the provided service to the current context.
Signature
declare const provideService: {
<I, S>(tag: Context.Tag<I, S>, service: S): <A, E, R>(self: Micro<A, E, R>) => Micro<A, E, Exclude<R, I>>
<A, E, R, I, S>(self: Micro<A, E, R>, tag: Context.Tag<I, S>, service: S): Micro<A, E, Exclude<R, I>>
}
Since v3.4.0
provideServiceEffect
Create a service using the provided Micro
effect, and add it to the current context.
Signature
declare const provideServiceEffect: {
<I, S, E2, R2>(
tag: Context.Tag<I, S>,
acquire: Micro<S, E2, R2>
): <A, E, R>(self: Micro<A, E, R>) => Micro<A, E | E2, Exclude<R, I> | R2>
<A, E, R, I, S, E2, R2>(
self: Micro<A, E, R>,
tag: Context.Tag<I, S>,
acquire: Micro<S, E2, R2>
): Micro<A, E | E2, Exclude<R, I> | R2>
}
Since v3.4.6
service
Access the given Context.Tag
from the environment.
Signature
declare const service: {
<I, S>(tag: Context.Reference<I, S>): Micro<S>
<I, S>(tag: Context.Tag<I, S>): Micro<S, never, I>
}
Since v3.4.0
serviceOption
Access the given Context.Tag
from the environment, without tracking the dependency at the type level.
It will return an Option
of the service, depending on whether it is available in the environment or not.
Signature
declare const serviceOption: <I, S>(tag: Context.Tag<I, S>) => Micro<Option.Option<S>>
Since v3.4.0
updateContext
Update the Context with the given mapping function.
Signature
declare const updateContext: {
<R2, R>(
f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>
): <A, E>(self: Micro<A, E, R>) => Micro<A, E, R2>
<A, E, R, R2>(self: Micro<A, E, R>, f: (context: Context.Context<R2>) => Context.Context<NoInfer<R>>): Micro<A, E, R2>
}
Since v3.11.0
updateService
Update the service for the given Context.Tag
in the environment.
Signature
declare const updateService: {
<I, A>(tag: Context.Reference<I, A>, f: (value: A) => A): <XA, E, R>(self: Micro<XA, E, R>) => Micro<XA, E, R>
<I, A>(tag: Context.Tag<I, A>, f: (value: A) => A): <XA, E, R>(self: Micro<XA, E, R>) => Micro<XA, E, R | I>
<XA, E, R, I, A>(self: Micro<XA, E, R>, tag: Context.Reference<I, A>, f: (value: A) => A): Micro<XA, E, R>
<XA, E, R, I, A>(self: Micro<XA, E, R>, tag: Context.Tag<I, A>, f: (value: A) => A): Micro<XA, E, R | I>
}
Since v3.11.0
environment refs
CurrentConcurrency (class)
Signature
declare class CurrentConcurrency
Since v3.11.0
CurrentScheduler (class)
Signature
declare class CurrentScheduler
Since v3.11.0
withConcurrency
If you have a Micro
that uses concurrency: "inherit"
, you can use this api to control the concurrency of that Micro
when it is run.
Example
import * as Micro from "effect/Micro"
Micro.forEach([1, 2, 3], (n) => Micro.succeed(n), {
concurrency: "inherit"
}).pipe(
Micro.withConcurrency(2) // use a concurrency of 2
)
Signature
declare const withConcurrency: {
(concurrency: "unbounded" | number): <A, E, R>(self: Micro<A, E, R>) => Micro<A, E, R>
<A, E, R>(self: Micro<A, E, R>, concurrency: "unbounded" | number): Micro<A, E, R>
}
Since v3.4.0
error handling
catchAll
Catch the error of the given Micro
effect, allowing you to recover from it.
It only catches expected errors.
Signature
declare const catchAll: {
<E, B, E2, R2>(f: (e: NoInfer<E>) => Micro<B, E2, R2>): <A, R>(self: Micro<A, E, R>) => Micro<A | B, E2, R | R2>
<A, E, R, B, E2, R2>(self: Micro<A, E, R>, f: (e: NoInfer<E>) => Micro<B, E2, R2>): Micro<A | B, E2, R | R2>
}
Since v3.4.6
catchAllCause
Catch the full MicroCause
object of the given Micro
effect, allowing you to recover from any kind of cause.
Signature
declare const catchAllCause: {
<E, B, E2, R2>(
f: (cause: NoInfer<MicroCause<E>>) => Micro<B, E2, R2>
): <A, R>(self: Micro<A, E, R>) => Micro<A | B, E2, R | R2>
<A, E, R, B, E2, R2>(
self: Micro<A, E, R>,
f: (cause: NoInfer<MicroCause<E>>) => Micro<B, E2, R2>
): Micro<A | B, E2, R | R2>
}
Since v3.4.6
catchAllDefect
Catch any unexpected errors of the given Micro
effect, allowing you to recover from them.
Signature
declare const catchAllDefect: {
<E, B, E2, R2>(f: (defect: unknown) => Micro<B, E2, R2>): <A, R>(self: Micro<A, E, R>) => Micro<A | B, E | E2, R | R2>
<A, E, R, B, E2, R2>(self: Micro<A, E, R>, f: (defect: unknown) => Micro<B, E2, R2>): Micro<A | B, E | E2, R | R2>
}
Since v3.4.6
catchCauseIf
Selectively catch a MicroCause
object of the given Micro
effect, using the provided predicate to determine if the failure should be caught.
Signature
declare const catchCauseIf: {
<E, B, E2, R2, EB extends MicroCause<E>>(
refinement: Refinement<MicroCause<E>, EB>,
f: (cause: EB) => Micro<B, E2, R2>
): <A, R>(self: Micro<A, E, R>) => Micro<A | B, Exclude<E, MicroCause.Error<EB>> | E2, R | R2>
<E, B, E2, R2>(
predicate: Predicate<MicroCause<NoInfer<E>>>,
f: (cause: NoInfer<MicroCause<E>>) => Micro<B, E2, R2>
): <A, R>(self: Micro<A, E, R>) => Micro<A | B, E | E2, R | R2>
<A, E, R, B, E2, R2, EB extends MicroCause<E>>(
self: Micro<A, E, R>,
refinement: Refinement<MicroCause<E>, EB>,
f: (cause: EB) => Micro<B, E2, R2>
): Micro<A | B, Exclude<E, MicroCause.Error<EB>> | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Micro<A, E, R>,
predicate: Predicate<MicroCause<NoInfer<E>>>,
f: (cause: NoInfer<MicroCause<E>>) => Micro<B, E2, R2>
): Micro<A | B, E | E2, R | R2>
}
Since v3.4.6
catchIf
Catch any expected errors that match the specified predicate.
Signature
declare const catchIf: {
<E, EB extends E, A2, E2, R2>(
refinement: Refinement<NoInfer<E>, EB>,
f: (e: EB) => Micro<A2, E2, R2>
): <A, R>(self: Micro<A, E, R>) => Micro<A2 | A, E2 | Exclude<E, EB>, R2 | R>
<E, A2, E2, R2>(
predicate: Predicate<NoInfer<E>>,
f: (e: NoInfer<E>) => Micro<A2, E2, R2>
): <A, R>(self: Micro<A, E, R>) => Micro<A2 | A, E | E2, R2 | R>
<A, E, R, EB extends E, A2, E2, R2>(
self: Micro<A, E, R>,
refinement: Refinement<E, EB>,
f: (e: EB) => Micro<A2, E2, R2>
): Micro<A | A2, E2 | Exclude<E, EB>, R | R2>
<A, E, R, A2, E2, R2>(
self: Micro<A, E, R>,
predicate: Predicate<E>,
f: (e: E) => Micro<A2, E2, R2>
): Micro<A | A2, E | E2, R | R2>
}
Since v3.4.0
catchTag
Recovers from the specified tagged error.
Signature
declare const catchTag: {
<K extends E extends { _tag: string } ? E["_tag"] : never, E, A1, E1, R1>(
k: K,
f: (e: Extract<E, { _tag: K }>) => Micro<A1, E1, R1>
): <A, R>(self: Micro<A, E, R>) => Micro<A1 | A, E1 | Exclude<E, { _tag: K }>, R1 | R>
<A, E, R, K extends E extends { _tag: string } ? E["_tag"] : never, R1, E1, A1>(
self: Micro<A, E, R>,
k: K,
f: (e: Extract<E, { _tag: K }>) => Micro<A1, E1, R1>
): Micro<A | A1, E1 | Exclude<E, { _tag: K }>, R | R1>
}
Since v3.4.0
either
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
.
Signature
declare const either: <A, E, R>(self: Micro<A, E, R>) => Micro<Either.Either<A, E>, never, R>
Since v3.4.0
ignore
Ignore any expected errors of the given Micro
effect, returning void
.
Signature
declare const ignore: <A, E, R>(self: Micro<A, E, R>) => Micro<void, never, R>
Since v3.4.0
ignoreLogged
Ignore any expected errors of the given Micro
effect, returning void
.
Signature
declare const ignoreLogged: <A, E, R>(self: Micro<A, E, R>) => Micro<void, never, R>
Since v3.4.0
mapError
Transform any expected errors of the given Micro
effect.
Signature
declare const mapError: {
<E, E2>(f: (e: E) => E2): <A, R>(self: Micro<A, E, R>) => Micro<A, E2, R>
<A, E, R, E2>(self: Micro<A, E, R>, f: (e: E) => E2): Micro<A, E2, R>
}
Since v3.4.0
mapErrorCause
Transform the full MicroCause
object of the given Micro
effect.
Signature
declare const mapErrorCause: {
<E, E2>(f: (e: MicroCause<E>) => MicroCause<E2>): <A, R>(self: Micro<A, E, R>) => Micro<A, E2, R>
<A, E, R, E2>(self: Micro<A, E, R>, f: (e: MicroCause<E>) => MicroCause<E2>): Micro<A, E2, R>
}
Since v3.4.6
option
Replace the success value of the given Micro
effect with an Option
, wrapping the success value in Some
and returning None
if the effect fails with an expected error.
Signature
declare const option: <A, E, R>(self: Micro<A, E, R>) => Micro<Option.Option<A>, never, R>
Since v3.4.0
orDie
Elevate any expected errors of the given Micro
effect to unexpected errors, resulting in an error type of never
.
Signature
declare const orDie: <A, E, R>(self: Micro<A, E, R>) => Micro<A, never, R>
Since v3.4.0
orElseSucceed
Recover from all errors by succeeding with the given value.
Signature
declare const orElseSucceed: {
<B>(f: LazyArg<B>): <A, E, R>(self: Micro<A, E, R>) => Micro<A | B, never, R>
<A, E, R, B>(self: Micro<A, E, R>, f: LazyArg<B>): Micro<A | B, never, R>
}
Since v3.4.0
retry
Retry the given Micro
effect using the provided options.
Signature
declare const retry: {
<A, E>(
options?:
| { while?: Predicate<E> | undefined; times?: number | undefined; schedule?: MicroSchedule | undefined }
| undefined
): <R>(self: Micro<A, E, R>) => Micro<A, E, R>
<A, E, R>(
self: Micro<A, E, R>,
options?:
| { while?: Predicate<E> | undefined; times?: number | undefined; schedule?: MicroSchedule | undefined }
| undefined
): Micro<A, E, R>
}
Since v3.4.0
tapDefect
Perform a side effect from unexpected errors of the given Micro
.
Signature
declare const tapDefect: {
<E, B, E2, R2>(f: (defect: unknown) => Micro<B, E2, R2>): <A, R>(self: Micro<A, E, R>) => Micro<A, E | E2, R | R2>
<A, E, R, B, E2, R2>(self: Micro<A, E, R>, f: (defect: unknown) => Micro<B, E2, R2>): Micro<A, E | E2, R | R2>
}
Since v3.4.6
tapError
Perform a side effect from expected errors of the given Micro
.
Signature
declare const tapError: {
<E, B, E2, R2>(f: (e: NoInfer<E>) => Micro<B, E2, R2>): <A, R>(self: Micro<A, E, R>) => Micro<A, E | E2, R | R2>
<A, E, R, B, E2, R2>(self: Micro<A, E, R>, f: (e: NoInfer<E>) => Micro<B, E2, R2>): Micro<A, E | E2, R | R2>
}
Since v3.4.6
tapErrorCause
Perform a side effect using the full MicroCause
object of the given Micro
.
Signature
declare const tapErrorCause: {
<E, B, E2, R2>(
f: (cause: NoInfer<MicroCause<E>>) => Micro<B, E2, R2>
): <A, R>(self: Micro<A, E, R>) => Micro<A, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Micro<A, E, R>,
f: (cause: NoInfer<MicroCause<E>>) => Micro<B, E2, R2>
): Micro<A, E | E2, R | R2>
}
Since v3.4.6
tapErrorCauseIf
Perform a side effect using if a MicroCause
object matches the specified predicate.
Signature
declare const tapErrorCauseIf: {
<E, B, E2, R2, EB extends MicroCause<E>>(
refinement: Refinement<MicroCause<E>, EB>,
f: (a: EB) => Micro<B, E2, R2>
): <A, R>(self: Micro<A, E, R>) => Micro<A, E | E2, R | R2>
<E, B, E2, R2>(
predicate: (cause: NoInfer<MicroCause<E>>) => boolean,
f: (a: NoInfer<MicroCause<E>>) => Micro<B, E2, R2>
): <A, R>(self: Micro<A, E, R>) => Micro<A, E | E2, R | R2>
<A, E, R, B, E2, R2, EB extends MicroCause<E>>(
self: Micro<A, E, R>,
refinement: Refinement<MicroCause<E>, EB>,
f: (a: EB) => Micro<B, E2, R2>
): Micro<A, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Micro<A, E, R>,
predicate: (cause: NoInfer<MicroCause<E>>) => boolean,
f: (a: NoInfer<MicroCause<E>>) => Micro<B, E2, R2>
): Micro<A, E | E2, R | R2>
}
Since v3.4.0
withTrace
Add a stack trace to any failures that occur in the effect. The trace will be added to the traces
field of the MicroCause
object.
Signature
declare const withTrace: {
(name: string): <A, E, R>(self: Micro<A, E, R>) => Micro<A, E, R>
<A, E, R>(self: Micro<A, E, R>, name: string): Micro<A, E, R>
}
Since v3.4.0
errors
Error
Signature
declare const Error: new <A extends Record<string, any> = {}>(
args: Equals<A, {}> extends true ? void : { readonly [P in keyof A]: A[P] }
) => YieldableError & Readonly<A>
Since v3.4.0
NoSuchElementException (class)
Represents a checked exception which occurs when an expected element was unable to be found.
Signature
declare class NoSuchElementException
Since v3.4.4
TaggedError
Signature
declare const TaggedError: <Tag extends string>(
tag: Tag
) => new <A extends Record<string, any> = {}>(
args: Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }
) => YieldableError & { readonly _tag: Tag } & Readonly<A>
Since v3.4.0
TimeoutException (class)
Represents a checked exception which occurs when a timeout occurs.
Signature
declare class TimeoutException
Since v3.4.4
YieldableError (interface)
Signature
export interface YieldableError extends Pipeable, Inspectable, Readonly<Error> {
readonly [Effectable.EffectTypeId]: Effect.VarianceStruct<never, this, never>
readonly [Effectable.StreamTypeId]: Stream.VarianceStruct<never, this, never>
readonly [Effectable.SinkTypeId]: Sink.VarianceStruct<never, unknown, never, this, never>
readonly [Effectable.ChannelTypeId]: Channel.VarianceStruct<never, unknown, this, unknown, never, unknown, never>
readonly [TypeId]: Micro.Variance<never, this, never>
[Symbol.iterator](): MicroIterator<Micro<never, this, never>>
}
Since v3.4.0
execution
runFork
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)
})
Signature
declare const runFork: <A, E>(
effect: Micro<A, E>,
options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: MicroScheduler | undefined } | undefined
) => MicroFiberImpl<A, E>
Since v3.4.0
runPromise
Execute the Micro
effect and return a Promise
that resolves with the successful value of the computation.
Signature
declare const runPromise: <A, E>(
effect: Micro<A, E>,
options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: MicroScheduler | undefined } | undefined
) => Promise<A>
Since v3.4.0
runPromiseExit
Execute the Micro
effect and return a Promise
that resolves with the MicroExit
of the computation.
Signature
declare const runPromiseExit: <A, E>(
effect: Micro<A, E>,
options?: { readonly signal?: AbortSignal | undefined; readonly scheduler?: MicroScheduler | undefined } | undefined
) => Promise<MicroExit<A, E>>
Since v3.4.6
runSync
Attempt to execute the Micro
effect synchronously and return the success value.
Signature
declare const runSync: <A, E>(effect: Micro<A, E>) => A
Since v3.4.0
runSyncExit
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
.
Signature
declare const runSyncExit: <A, E>(effect: Micro<A, E>) => MicroExit<A, E>
Since v3.4.6
fiber & forking
fork
Run the Micro
effect in a new MicroFiber
that can be awaited, joined, or aborted.
When the parent Micro
finishes, this Micro
will be aborted.
Signature
declare const fork: <A, E, R>(self: Micro<A, E, R>) => Micro<MicroFiber<A, E>, never, R>
Since v3.4.0
forkDaemon
Run the Micro
effect in a new MicroFiber
that can be awaited, joined, or aborted.
It will not be aborted when the parent Micro
finishes.
Signature
declare const forkDaemon: <A, E, R>(self: Micro<A, E, R>) => Micro<MicroFiber<A, E>, never, R>
Since v3.4.0
forkIn
Run the Micro
effect in a new MicroFiber
that can be awaited, joined, or aborted.
The lifetime of the handle will be attached to the provided MicroScope
.
Signature
declare const forkIn: {
(scope: MicroScope): <A, E, R>(self: Micro<A, E, R>) => Micro<MicroFiber<A, E>, never, R>
<A, E, R>(self: Micro<A, E, R>, scope: MicroScope): Micro<MicroFiber<A, E>, never, R>
}
Since v3.4.0
forkScoped
Run the Micro
effect in a new MicroFiber
that can be awaited, joined, or aborted.
The lifetime of the handle will be attached to the current MicroScope
.
Signature
declare const forkScoped: <A, E, R>(self: Micro<A, E, R>) => Micro<MicroFiber<A, E>, never, R | MicroScope>
Since v3.4.0
filtering & conditionals
filterOrFail
Filter the specified effect with the provided function, failing with specified error if the predicate fails.
In addition to the filtering capabilities discussed earlier, you have the option to further refine and narrow down the type of the success channel by providing a
Signature
declare const filterOrFail: {
<A, B extends A, E2>(
refinement: Refinement<A, B>,
orFailWith: (a: NoInfer<A>) => E2
): <E, R>(self: Micro<A, E, R>) => Micro<B, E2 | E, R>
<A, E2>(
predicate: Predicate<NoInfer<A>>,
orFailWith: (a: NoInfer<A>) => E2
): <E, R>(self: Micro<A, E, R>) => Micro<A, E2 | E, R>
<A, E, R, B extends A, E2>(
self: Micro<A, E, R>,
refinement: Refinement<A, B>,
orFailWith: (a: A) => E2
): Micro<B, E | E2, R>
<A, E, R, E2>(self: Micro<A, E, R>, predicate: Predicate<A>, orFailWith: (a: A) => E2): Micro<A, E | E2, R>
}
Since v3.4.0
filterOrFailCause
Filter the specified effect with the provided function, failing with specified MicroCause
if the predicate fails.
In addition to the filtering capabilities discussed earlier, you have the option to further refine and narrow down the type of the success channel by providing a
Signature
declare const filterOrFailCause: {
<A, B extends A, E2>(
refinement: Refinement<A, B>,
orFailWith: (a: NoInfer<A>) => MicroCause<E2>
): <E, R>(self: Micro<A, E, R>) => Micro<B, E2 | E, R>
<A, E2>(
predicate: Predicate<NoInfer<A>>,
orFailWith: (a: NoInfer<A>) => MicroCause<E2>
): <E, R>(self: Micro<A, E, R>) => Micro<A, E2 | E, R>
<A, E, R, B extends A, E2>(
self: Micro<A, E, R>,
refinement: Refinement<A, B>,
orFailWith: (a: A) => MicroCause<E2>
): Micro<B, E | E2, R>
<A, E, R, E2>(
self: Micro<A, E, R>,
predicate: Predicate<A>,
orFailWith: (a: A) => MicroCause<E2>
): Micro<A, E | E2, R>
}
Since v3.4.0
when
The moral equivalent of if (p) exp
.
Signature
declare const when: {
<E2 = never, R2 = never>(
condition: LazyArg<boolean> | Micro<boolean, E2, R2>
): <A, E, R>(self: Micro<A, E, R>) => Micro<Option.Option<A>, E | E2, R | R2>
<A, E, R, E2 = never, R2 = never>(
self: Micro<A, E, R>,
condition: LazyArg<boolean> | Micro<boolean, E2, R2>
): Micro<Option.Option<A>, E | E2, R | R2>
}
Since v3.4.0
flags
interruptible
Flag the effect as interruptible, which means that when the effect is interrupted, it will be interrupted immediately.
Signature
declare const interruptible: <A, E, R>(self: Micro<A, E, R>) => Micro<A, E, R>
Since v3.4.0
uninterruptible
Flag the effect as uninterruptible, which means that when the effect is interrupted, it will be allowed to continue running until completion.
Signature
declare const uninterruptible: <A, E, R>(self: Micro<A, E, R>) => Micro<A, E, R>
Since v3.4.0
guards
isMicro
Signature
declare const isMicro: (u: unknown) => u is Micro<any, any, any>
Since v3.4.0
isMicroCause
Signature
declare const isMicroCause: (self: unknown) => self is MicroCause<unknown>
Since v3.6.6
interruption
interrupt
Abort the current Micro
effect.
Signature
declare const interrupt: Micro<never, never, never>
Since v3.4.6
uninterruptibleMask
Wrap the given Micro
effect in an uninterruptible region, preventing the effect from being aborted.
You can use the restore
function to restore a Micro
effect to the interruptibility state before the uninterruptibleMask
was applied.
Example
import * as Micro from "effect/Micro"
Micro.uninterruptibleMask((restore) =>
Micro.sleep(1000).pipe(
// uninterruptible
Micro.andThen(restore(Micro.sleep(1000))) // interruptible
)
)
Signature
declare const uninterruptibleMask: <A, E, R>(
f: (restore: <A, E, R>(effect: Micro<A, E, R>) => Micro<A, E, R>) => Micro<A, E, R>
) => Micro<A, E, R>
Since v3.4.0
mapping & sequencing
andThen
A more flexible version of flatMap
that combines map
and flatMap
into a single API.
It also lets you directly pass a Micro
effect, which will be executed after the current effect.
Signature
declare const andThen: {
<A, X>(
f: (a: A) => X
): <E, R>(
self: Micro<A, E, R>
) => [X] extends [Micro<infer A1, infer E1, infer R1>] ? Micro<A1, E | E1, R | R1> : Micro<X, E, R>
<X>(
f: NotFunction<X>
): <A, E, R>(
self: Micro<A, E, R>
) => [X] extends [Micro<infer A1, infer E1, infer R1>] ? Micro<A1, E | E1, R | R1> : Micro<X, E, R>
<A, E, R, X>(
self: Micro<A, E, R>,
f: (a: A) => X
): [X] extends [Micro<infer A1, infer E1, infer R1>] ? Micro<A1, E | E1, R | R1> : Micro<X, E, R>
<A, E, R, X>(
self: Micro<A, E, R>,
f: NotFunction<X>
): [X] extends [Micro<infer A1, infer E1, infer R1>] ? Micro<A1, E | E1, R | R1> : Micro<X, E, R>
}
Since v3.4.0
as
Create a Micro
effect that will replace the success value of the given effect.
Signature
declare const as: {
<A, B>(value: B): <E, R>(self: Micro<A, E, R>) => Micro<B, E, R>
<A, E, R, B>(self: Micro<A, E, R>, value: B): Micro<B, E, R>
}
Since v3.4.0
asSome
Wrap the success value of this Micro
effect in a Some
.
Signature
declare const asSome: <A, E, R>(self: Micro<A, E, R>) => Micro<Option.Option<A>, E, R>
Since v3.4.0
asVoid
Replace the success value of the Micro
effect with void
.
Signature
declare const asVoid: <A, E, R>(self: Micro<A, E, R>) => Micro<void, E, R>
Since v3.4.0
exit
Access the MicroExit
of the given Micro
effect.
Signature
declare const exit: <A, E, R>(self: Micro<A, E, R>) => Micro<MicroExit<A, E>, never, R>
Since v3.4.6
flatMap
Map the success value of this Micro
effect to another Micro
effect, then flatten the result.
Signature
declare const flatMap: {
<A, B, E2, R2>(f: (a: A) => Micro<B, E2, R2>): <E, R>(self: Micro<A, E, R>) => Micro<B, E | E2, R | R2>
<A, E, R, B, E2, R2>(self: Micro<A, E, R>, f: (a: A) => Micro<B, E2, R2>): Micro<B, E | E2, R | R2>
}
Since v3.4.0
flatten
Flattens any nested Micro
effects, merging the error and requirement types.
Signature
declare const flatten: <A, E, R, E2, R2>(self: Micro<Micro<A, E, R>, E2, R2>) => Micro<A, E | E2, R | R2>
Since v3.4.0
flip
Swap the error and success types of the Micro
effect.
Signature
declare const flip: <A, E, R>(self: Micro<A, E, R>) => Micro<E, A, R>
Since v3.4.0
map
Transforms the success value of the Micro
effect with the specified function.
Signature
declare const map: {
<A, B>(f: (a: A) => B): <E, R>(self: Micro<A, E, R>) => Micro<B, E, R>
<A, E, R, B>(self: Micro<A, E, R>, f: (a: A) => B): Micro<B, E, R>
}
Since v3.4.0
sandbox
Replace the error type of the given Micro
with the full MicroCause
object.
Signature
declare const sandbox: <A, E, R>(self: Micro<A, E, R>) => Micro<A, MicroCause<E>, R>
Since v3.4.0
tap
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.
Signature
declare const tap: {
<A, X>(
f: (a: NoInfer<A>) => X
): <E, R>(
self: Micro<A, E, R>
) => [X] extends [Micro<infer _A1, infer E1, infer R1>] ? Micro<A, E | E1, R | R1> : Micro<A, E, R>
<X>(
f: NotFunction<X>
): <A, E, R>(
self: Micro<A, E, R>
) => [X] extends [Micro<infer _A1, infer E1, infer R1>] ? Micro<A, E | E1, R | R1> : Micro<A, E, R>
<A, E, R, X>(
self: Micro<A, E, R>,
f: (a: NoInfer<A>) => X
): [X] extends [Micro<infer _A1, infer E1, infer R1>] ? Micro<A, E | E1, R | R1> : Micro<A, E, R>
<A, E, R, X>(
self: Micro<A, E, R>,
f: NotFunction<X>
): [X] extends [Micro<infer _A1, infer E1, infer R1>] ? Micro<A, E | E1, R | R1> : Micro<A, E, R>
}
Since v3.4.0
models
Micro (interface)
A lightweight alternative to the Effect
data type, with a subset of the functionality.
Signature
export interface Micro<out A, out E = never, out R = never> extends Effect<A, E, R> {
readonly [TypeId]: Micro.Variance<A, E, R>
[Symbol.iterator](): MicroIterator<Micro<A, E, R>>
[Unify.typeSymbol]?: unknown
[Unify.unifySymbol]?: MicroUnify<this>
[Unify.ignoreSymbol]?: MicroUnifyIgnore
}
Since v3.4.0
MicroIterator (interface)
Signature
export interface MicroIterator<T extends Micro<any, any, any>> {
next(...args: ReadonlyArray<any>): IteratorResult<YieldWrap<T>, Micro.Success<T>>
}
Since v3.4.0
MicroUnify (interface)
Signature
export interface MicroUnify<A extends { [Unify.typeSymbol]?: any }> extends EffectUnify<A> {
Micro?: () => A[Unify.typeSymbol] extends Micro<infer A0, infer E0, infer R0> | infer _ ? Micro<A0, E0, R0> : never
}
Since v3.4.3
MicroUnifyIgnore (interface)
Signature
export interface MicroUnifyIgnore extends EffectUnifyIgnore {
Effect?: true
}
Since v3.4.3
pattern matching
match
Signature
declare const match: {
<E, A2, A, A3>(options: {
readonly onFailure: (error: E) => A2
readonly onSuccess: (value: A) => A3
}): <R>(self: Micro<A, E, R>) => Micro<A2 | A3, never, R>
<A, E, R, A2, A3>(
self: Micro<A, E, R>,
options: { readonly onFailure: (error: E) => A2; readonly onSuccess: (value: A) => A3 }
): Micro<A2 | A3, never, R>
}
Since v3.4.0
matchCause
Signature
declare const matchCause: {
<E, A2, A, A3>(options: {
readonly onFailure: (cause: MicroCause<E>) => A2
readonly onSuccess: (a: A) => A3
}): <R>(self: Micro<A, E, R>) => Micro<A2 | A3, never, R>
<A, E, R, A2, A3>(
self: Micro<A, E, R>,
options: { readonly onFailure: (cause: MicroCause<E>) => A2; readonly onSuccess: (a: A) => A3 }
): Micro<A2 | A3, never, R>
}
Since v3.4.6
matchCauseEffect
Signature
declare const matchCauseEffect: {
<E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (cause: MicroCause<E>) => Micro<A2, E2, R2>
readonly onSuccess: (a: A) => Micro<A3, E3, R3>
}): <R>(self: Micro<A, E, R>) => Micro<A2 | A3, E2 | E3, R2 | R3 | R>
<A, E, R, A2, E2, R2, A3, E3, R3>(
self: Micro<A, E, R>,
options: {
readonly onFailure: (cause: MicroCause<E>) => Micro<A2, E2, R2>
readonly onSuccess: (a: A) => Micro<A3, E3, R3>
}
): Micro<A2 | A3, E2 | E3, R2 | R3 | R>
}
Since v3.4.6
matchEffect
Signature
declare const matchEffect: {
<E, A2, E2, R2, A, A3, E3, R3>(options: {
readonly onFailure: (e: E) => Micro<A2, E2, R2>
readonly onSuccess: (a: A) => Micro<A3, E3, R3>
}): <R>(self: Micro<A, E, R>) => Micro<A2 | A3, E2 | E3, R2 | R3 | R>
<A, E, R, A2, E2, R2, A3, E3, R3>(
self: Micro<A, E, R>,
options: { readonly onFailure: (e: E) => Micro<A2, E2, R2>; readonly onSuccess: (a: A) => Micro<A3, E3, R3> }
): Micro<A2 | A3, E2 | E3, R2 | R3 | R>
}
Since v3.4.6
references
MaxOpsBeforeYield (class)
Signature
declare class MaxOpsBeforeYield
Since v3.11.0
repetition
forever
Repeat the given Micro
effect forever, only stopping if the effect fails.
Signature
declare const forever: <A, E, R>(self: Micro<A, E, R>) => Micro<never, E, R>
Since v3.4.0
repeat
Repeat the given Micro
effect using the provided options. Only successful results will be repeated.
Signature
declare const repeat: {
<A, E>(
options?:
| { while?: Predicate<A> | undefined; times?: number | undefined; schedule?: MicroSchedule | undefined }
| undefined
): <R>(self: Micro<A, E, R>) => Micro<A, E, R>
<A, E, R>(
self: Micro<A, E, R>,
options?:
| { while?: Predicate<A> | undefined; times?: number | undefined; schedule?: MicroSchedule | undefined }
| undefined
): Micro<A, E, R>
}
Since v3.4.0
repeatExit
Repeat the given Micro
using the provided options.
The while
predicate will be checked after each iteration, and can use the fall MicroExit
of the effect to determine if the repetition should continue.
Signature
declare const repeatExit: {
<A, E>(options: {
while: Predicate<MicroExit<A, E>>
times?: number | undefined
schedule?: MicroSchedule | undefined
}): <R>(self: Micro<A, E, R>) => Micro<A, E, R>
<A, E, R>(
self: Micro<A, E, R>,
options: { while: Predicate<MicroExit<A, E>>; times?: number | undefined; schedule?: MicroSchedule | undefined }
): Micro<A, E, R>
}
Since v3.4.6
replicate
Replicates the given effect n
times.
Signature
declare const replicate: {
(n: number): <A, E, R>(self: Micro<A, E, R>) => Array<Micro<A, E, R>>
<A, E, R>(self: Micro<A, E, R>, n: number): Array<Micro<A, E, R>>
}
Since v3.11.0
replicateEffect
Performs this effect the specified number of times and collects the results.
Signature
declare const replicateEffect: {
(
n: number,
options?: { readonly concurrency?: Concurrency | undefined; readonly discard?: false | undefined }
): <A, E, R>(self: Micro<A, E, R>) => Micro<Array<A>, E, R>
(
n: number,
options: { readonly concurrency?: Concurrency | undefined; readonly discard: true }
): <A, E, R>(self: Micro<A, E, R>) => Micro<void, E, R>
<A, E, R>(
self: Micro<A, E, R>,
n: number,
options?: { readonly concurrency?: Concurrency | undefined; readonly discard?: false | undefined }
): Micro<Array<A>, E, R>
<A, E, R>(
self: Micro<A, E, R>,
n: number,
options: { readonly concurrency?: Concurrency | undefined; readonly discard: true }
): Micro<void, E, R>
}
Since v3.11.0
resources & finalization
MicroScope
Signature
declare const MicroScope: Context.Tag<MicroScope, MicroScope>
Since v3.4.0
MicroScope (interface)
Signature
export interface MicroScope {
readonly [MicroScopeTypeId]: MicroScopeTypeId
readonly addFinalizer: (finalizer: (exit: MicroExit<unknown, unknown>) => Micro<void>) => Micro<void>
readonly fork: Micro<MicroScope.Closeable>
}
Since v3.4.0
MicroScope (namespace)
Since v3.4.0
Closeable (interface)
Signature
export interface Closeable extends MicroScope {
readonly close: (exit: MicroExit<any, any>) => Micro<void>
}
Since v3.4.0
MicroScopeTypeId
Signature
declare const MicroScopeTypeId: unique symbol
Since v3.4.0
MicroScopeTypeId (type alias)
Signature
type MicroScopeTypeId = typeof MicroScopeTypeId
Since v3.4.0
acquireRelease
Create a resource with a cleanup Micro
effect, ensuring the cleanup is executed when the MicroScope
is closed.
Signature
declare const acquireRelease: <A, E, R>(
acquire: Micro<A, E, R>,
release: (a: A, exit: MicroExit<unknown, unknown>) => Micro<void>
) => Micro<A, E, R | MicroScope>
Since v3.4.0
acquireUseRelease
Acquire a resource, use it, and then release the resource when the use
effect has completed.
Signature
declare const acquireUseRelease: <Resource, E, R, A, E2, R2, E3, R3>(
acquire: Micro<Resource, E, R>,
use: (a: Resource) => Micro<A, E2, R2>,
release: (a: Resource, exit: MicroExit<A, E2>) => Micro<void, E3, R3>
) => Micro<A, E | E2 | E3, R | R2 | R3>
Since v3.4.0
addFinalizer
Add a finalizer to the current MicroScope
.
Signature
declare const addFinalizer: (
finalizer: (exit: MicroExit<unknown, unknown>) => Micro<void>
) => Micro<void, never, MicroScope>
Since v3.4.0
ensuring
Regardless of the result of the this Micro
effect, run the finalizer effect.
Signature
declare const ensuring: {
<XE, XR>(finalizer: Micro<void, XE, XR>): <A, E, R>(self: Micro<A, E, R>) => Micro<A, E | XE, R | XR>
<A, E, R, XE, XR>(self: Micro<A, E, R>, finalizer: Micro<void, XE, XR>): Micro<A, E | XE, R | XR>
}
Since v3.4.0
onError
When the Micro
effect fails, run the given finalizer effect with the MicroCause
of the executed effect.
Signature
declare const onError: {
<A, E, XE, XR>(
f: (cause: MicroCause<NoInfer<E>>) => Micro<void, XE, XR>
): <R>(self: Micro<A, E, R>) => Micro<A, E | XE, R | XR>
<A, E, R, XE, XR>(
self: Micro<A, E, R>,
f: (cause: MicroCause<NoInfer<E>>) => Micro<void, XE, XR>
): Micro<A, E | XE, R | XR>
}
Since v3.4.6
onExit
When the Micro
effect is completed, run the given finalizer effect with the MicroExit
of the executed effect.
Signature
declare const onExit: {
<A, E, XE, XR>(
f: (exit: MicroExit<A, E>) => Micro<void, XE, XR>
): <R>(self: Micro<A, E, R>) => Micro<A, E | XE, R | XR>
<A, E, R, XE, XR>(self: Micro<A, E, R>, f: (exit: MicroExit<A, E>) => Micro<void, XE, XR>): Micro<A, E | XE, R | XR>
}
Since v3.4.6
onExitIf
When the Micro
effect is completed, run the given finalizer effect if it matches the specified predicate.
Signature
declare const onExitIf: {
<A, E, XE, XR, B extends MicroExit<A, E>>(
refinement: Refinement<MicroExit<A, E>, B>,
f: (exit: B) => Micro<void, XE, XR>
): <R>(self: Micro<A, E, R>) => Micro<A, E | XE, R | XR>
<A, E, XE, XR>(
predicate: Predicate<MicroExit<NoInfer<A>, NoInfer<E>>>,
f: (exit: MicroExit<NoInfer<A>, NoInfer<E>>) => Micro<void, XE, XR>
): <R>(self: Micro<A, E, R>) => Micro<A, E | XE, R | XR>
<A, E, R, XE, XR, B extends MicroExit<A, E>>(
self: Micro<A, E, R>,
refinement: Refinement<MicroExit<A, E>, B>,
f: (exit: B) => Micro<void, XE, XR>
): Micro<A, E | XE, R | XR>
<A, E, R, XE, XR>(
self: Micro<A, E, R>,
predicate: Predicate<MicroExit<NoInfer<A>, NoInfer<E>>>,
f: (exit: MicroExit<NoInfer<A>, NoInfer<E>>) => Micro<void, XE, XR>
): Micro<A, E | XE, R | XR>
}
Since v3.4.6
onInterrupt
If this Micro
effect is aborted, run the finalizer effect.
Signature
declare const onInterrupt: {
<XE, XR>(finalizer: Micro<void, XE, XR>): <A, E, R>(self: Micro<A, E, R>) => Micro<A, E | XE, R | XR>
<A, E, R, XE, XR>(self: Micro<A, E, R>, finalizer: Micro<void, XE, XR>): Micro<A, E | XE, R | XR>
}
Since v3.4.6
provideScope
Provide a MicroScope
to an effect.
Signature
declare const provideScope: {
(scope: MicroScope): <A, E, R>(self: Micro<A, E, R>) => Micro<A, E, Exclude<R, MicroScope>>
<A, E, R>(self: Micro<A, E, R>, scope: MicroScope): Micro<A, E, Exclude<R, MicroScope>>
}
Since v3.4.0
scope
Access the current MicroScope
.
Signature
declare const scope: Micro<MicroScope, never, MicroScope>
Since v3.4.0
scopeMake
Signature
declare const scopeMake: Micro<MicroScope.Closeable, never, never>
Since v3.4.0
scopeUnsafeMake
Signature
declare const scopeUnsafeMake: () => MicroScope.Closeable
Since v3.4.0
scoped
Provide a MicroScope
to the given effect, closing it after the effect has finished executing.
Signature
declare const scoped: <A, E, R>(self: Micro<A, E, R>) => Micro<A, E, Exclude<R, MicroScope>>
Since v3.4.0
scheduler
MicroScheduler (interface)
Signature
export interface MicroScheduler {
readonly scheduleTask: (task: () => void, priority: number) => void
readonly shouldYield: (fiber: MicroFiber<unknown, unknown>) => boolean
readonly flush: () => void
}
Since v3.5.9
MicroSchedulerDefault (class)
Signature
declare class MicroSchedulerDefault
Since v3.5.9
scheduleTask (method)
Signature
declare const scheduleTask: (task: () => void, _priority: number) => void
Since v3.5.9
runTasks (method)
Signature
declare const runTasks: () => void
Since v3.5.9
shouldYield (method)
Signature
declare const shouldYield: (fiber: MicroFiber<unknown, unknown>) => boolean
Since v3.5.9
flush (method)
Signature
declare const flush: () => void
Since v3.5.9
afterScheduled (property)
Signature
afterScheduled: () => void
Since v3.5.9
scheduling
MicroSchedule (type alias)
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.
Signature
type MicroSchedule = (attempt: number, elapsed: number) => Option.Option<number>
Since v3.4.6
scheduleAddDelay
Returns a new MicroSchedule
with an added calculated delay to each delay returned by this schedule.
Signature
declare const scheduleAddDelay: {
(f: () => number): (self: MicroSchedule) => MicroSchedule
(self: MicroSchedule, f: () => number): MicroSchedule
}
Since v3.4.6
scheduleExponential
Create a MicroSchedule
that will generate a delay with an exponential backoff.
Signature
declare const scheduleExponential: (baseMillis: number, factor?: number) => MicroSchedule
Since v3.4.6
scheduleIntersect
Combines two MicroSchedule
s, by recurring only if both schedules want to recur, using the maximum of the two durations between recurrences.
Signature
declare const scheduleIntersect: {
(that: MicroSchedule): (self: MicroSchedule) => MicroSchedule
(self: MicroSchedule, that: MicroSchedule): MicroSchedule
}
Since v3.4.6
scheduleRecurs
Create a MicroSchedule
that will stop repeating after the specified number of attempts.
Signature
declare const scheduleRecurs: (n: number) => MicroSchedule
Since v3.4.6
scheduleSpaced
Create a MicroSchedule
that will generate a constant delay.
Signature
declare const scheduleSpaced: (millis: number) => MicroSchedule
Since v3.4.6
scheduleUnion
Combines two MicroSchedule
s, by recurring if either schedule wants to recur, using the minimum of the two durations between recurrences.
Signature
declare const scheduleUnion: {
(that: MicroSchedule): (self: MicroSchedule) => MicroSchedule
(self: MicroSchedule, that: MicroSchedule): MicroSchedule
}
Since v3.4.6
scheduleWithMaxDelay
Transform a MicroSchedule
to one that will have a delay that will never exceed the specified maximum.
Signature
declare const scheduleWithMaxDelay: {
(max: number): (self: MicroSchedule) => MicroSchedule
(self: MicroSchedule, max: number): MicroSchedule
}
Since v3.4.6
scheduleWithMaxElapsed
Transform a MicroSchedule
to one that will stop repeating after the specified amount of time.
Signature
declare const scheduleWithMaxElapsed: {
(max: number): (self: MicroSchedule) => MicroSchedule
(self: MicroSchedule, max: number): MicroSchedule
}
Since v3.4.6
sequencing
race
Returns an effect that races two effects, yielding the value of the first effect to succeed. Losers of the race will be interrupted immediately.
Signature
declare const race: {
<A2, E2, R2>(that: Micro<A2, E2, R2>): <A, E, R>(self: Micro<A, E, R>) => Micro<A | A2, E | E2, R | R2>
<A, E, R, A2, E2, R2>(self: Micro<A, E, R>, that: Micro<A2, E2, R2>): Micro<A | A2, E | E2, R | R2>
}
Since v3.4.0
raceAll
Returns an effect that races all the specified effects, yielding the value of the first effect to succeed with a value. Losers of the race will be interrupted immediately
Signature
declare const raceAll: <Eff extends Micro<any, any, any>>(
all: Iterable<Eff>
) => Micro<Micro.Success<Eff>, Micro.Error<Eff>, Micro.Context<Eff>>
Since v3.4.0
raceAllFirst
Returns an effect that races all the specified effects, yielding the value of the first effect to succeed or fail. Losers of the race will be interrupted immediately.
Signature
declare const raceAllFirst: <Eff extends Micro<any, any, any>>(
all: Iterable<Eff>
) => Micro<Micro.Success<Eff>, Micro.Error<Eff>, Micro.Context<Eff>>
Since v3.4.0
raceFirst
Returns an effect that races two effects, yielding the value of the first effect to succeed or fail. Losers of the race will be interrupted immediately.
Signature
declare const raceFirst: {
<A2, E2, R2>(that: Micro<A2, E2, R2>): <A, E, R>(self: Micro<A, E, R>) => Micro<A | A2, E | E2, R | R2>
<A, E, R, A2, E2, R2>(self: Micro<A, E, R>, that: Micro<A2, E2, R2>): Micro<A | A2, E | E2, R | R2>
}
Since v3.4.0
type ids
TypeId
Signature
declare const TypeId: unique symbol
Since v3.4.0
TypeId (type alias)
Signature
type TypeId = typeof TypeId
Since v3.4.0
type lambdas
MicroTypeLambda (interface)
Signature
export interface MicroTypeLambda extends TypeLambda {
readonly type: Micro<this["Target"], this["Out1"], this["Out2"]>
}
Since v3.4.1
utils
All (namespace)
Since v3.4.0
MicroAny (type alias)
Signature
type MicroAny = Micro<any, any, any>
Since v3.4.0
ReturnIterable (type alias)
Signature
type ReturnIterable<T, Discard> = [T] extends [Iterable<Micro<infer A, infer E, infer R>>]
? Micro<Discard extends true ? void : Array<A>, E, R>
: never
Since v3.4.0
ReturnTuple (type alias)
Signature
type Micro<Discard extends true ? void : T[number] extends never ? [] : { -readonly [K in keyof T]: T[K] extends Micro<infer _A, infer _E, infer _R> ? _A : never; }, T[number] extends never ? never : T[number] extends Micro<infer _A, infer _E, infer _R> ? _E : never, T[number] extends never ? never : T[number] extends Micro<infer _A, infer _E, infer _R> ? _R : never> = Micro<
Discard extends true ? void
: T[number] extends never ? []
: { -readonly [K in keyof T]: T[K] extends Micro<infer _A, infer _E, infer _R> ? _A : never },
T[number] extends never ? never
: T[number] extends Micro<infer _A, infer _E, infer _R> ? _E
: never,
T[number] extends never ? never
: T[number] extends Micro<infer _A, infer _E, infer _R> ? _R
: never
> extends infer X ? X : never
Since v3.4.0
ReturnObject (type alias)
Signature
type ReturnObject<T, Discard> = [T] extends [{ [K: string]: MicroAny }]
? Micro<
Discard extends true
? void
: { -readonly [K in keyof T]: [T[K]] extends [Micro<infer _A, infer _E, infer _R>] ? _A : never },
keyof T extends never ? never : T[keyof T] extends Micro<infer _A, infer _E, infer _R> ? _E : never,
keyof T extends never ? never : T[keyof T] extends Micro<infer _A, infer _E, infer _R> ? _R : never
>
: never
Since v3.4.0
IsDiscard (type alias)
Signature
type IsDiscard<A> = [Extract<A, { readonly discard: true }>] extends [never] ? false : true
Since v3.4.0
Return (type alias)
Signature
type Return<Arg, O> = [Arg] extends [ReadonlyArray<MicroAny>]
? ReturnTuple<Arg, IsDiscard<O>>
: [Arg] extends [Iterable<MicroAny>]
? ReturnIterable<Arg, IsDiscard<O>>
: [Arg] extends [Record<string, MicroAny>]
? ReturnObject<Arg, IsDiscard<O>>
: never
Since v3.4.0
Micro (namespace)
Since v3.4.0
Variance (interface)
Signature
export interface Variance<A, E, R> {
_A: Covariant<A>
_E: Covariant<E>
_R: Covariant<R>
}
Since v3.4.0
Success (type alias)
Signature
type Success<T> = T extends Micro<infer _A, infer _E, infer _R> ? _A : never
Since v3.4.0
Error (type alias)
Signature
type Error<T> = T extends Micro<infer _A, infer _E, infer _R> ? _E : never
Since v3.4.0
Context (type alias)
Signature
type Context<T> = T extends Micro<infer _A, infer _E, infer _R> ? _R : never
Since v3.4.0
zipping
zip
Combine two Micro
effects into a single effect that produces a tuple of their results.
Signature
declare const zip: {
<A2, E2, R2>(
that: Micro<A2, E2, R2>,
options?: { readonly concurrent?: boolean | undefined } | undefined
): <A, E, R>(self: Micro<A, E, R>) => Micro<[A, A2], E2 | E, R2 | R>
<A, E, R, A2, E2, R2>(
self: Micro<A, E, R>,
that: Micro<A2, E2, R2>,
options?: { readonly concurrent?: boolean | undefined }
): Micro<[A, A2], E | E2, R | R2>
}
Since v3.4.0
zipWith
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.
Signature
declare const zipWith: {
<A2, E2, R2, A, B>(
that: Micro<A2, E2, R2>,
f: (a: A, b: A2) => B,
options?: { readonly concurrent?: boolean | undefined }
): <E, R>(self: Micro<A, E, R>) => Micro<B, E2 | E, R2 | R>
<A, E, R, A2, E2, R2, B>(
self: Micro<A, E, R>,
that: Micro<A2, E2, R2>,
f: (a: A, b: A2) => B,
options?: { readonly concurrent?: boolean | undefined }
): Micro<B, E2 | E, R2 | R>
}
Since v3.4.3