IO<R, E, A> represents a lazy, composable effect.
Requirements (environment/dependencies needed to run)
Error type (typed failures)
Success type (value produced on success)
Makes IO iterable for generator do-notation (yield* syntax). Yields the IO itself, allowing IO.gen to extract the value.
Catches all errors (alias for recoverWith).
Catches errors with a specific tag and handles them.
The error tag to catch
Handler for the caught error
Delays execution by the specified milliseconds.
Chains another IO effect based on the success value.
Function returning next IO effect
New IO with combined effects
Flattens a nested IO.
Pattern matches on success and failure.
Handler for failures
Handler for successes
New IO with handled result
Transforms the success value.
Function to apply to the success value
New IO with transformed value
Transforms the error value.
Function to apply to the error
New IO with transformed error
Pattern matches with object pattern syntax.
Pipes the IO through a function.
Provides a context to satisfy the requirements of this effect.
The context containing required services
Provides services using a layer.
The layer that provides services
Provides a single service to satisfy part of the requirements.
The service tag
The service implementation
Recovers from any error with a fallback value.
Value to use on error
New IO that never fails
Recovers from error by running another effect.
Function returning recovery effect
New IO with error handling
Retries the effect up to n times on failure.
Maximum number of retries
Retries the effect with a delay between attempts.
Delay between retries in milliseconds
Runs the effect and returns an Either. Never throws. This is the safe default - all errors become Left. Requires R = never.
Runs the effect and returns an Exit.
Runs the effect and returns an Option. Some(value) on success, None on failure.
Runs the effect and returns a Promise of the value. Throws on any error (typed E, defect, or interrupt). Requires R = never.
Runs a sync effect and returns an Either. Never throws. This is the safe default - all errors become Left. Throws only if the effect is async (cannot be made safe synchronously). Requires R = never.
Runs a sync effect and returns the value. Throws on any error or if the effect is async. Requires R = never.
Runs the effect and returns a Try. Success(value) on success, Failure(error) on failure.
Applies a side effect without changing the value.
Side effect function
Same IO for chaining
Applies an effectful side effect without changing the value.
Function returning IO for side effect
Same value after running side effect
Executes a side effect on the error without changing it. Useful for logging errors while preserving the error chain.
Side effect function to run on error
Same IO with the side effect attached
const io = IO.asyncResult(() => query(), toError) .tapError(err => console.error('Query failed:', err)) .map(data => transform(data)) Copy
const io = IO.asyncResult(() => query(), toError) .tapError(err => console.error('Query failed:', err)) .map(data => transform(data))
Fails with TimeoutError if the effect doesn't complete within the specified duration.
Maximum time in milliseconds
Returns a fallback value if the effect doesn't complete within the specified duration.
Value to return on timeout
Converts to JSON representation.
Converts to string representation.
Zips two IOs into a tuple.
Sequences two IOs, keeping the first value.
Sequences two IOs, keeping the second value.
IO<R, E, A> represents a lazy, composable effect.