variable / @typed/fx/Fx

unwrap

Unwraps an Effect that produces an Fx into a single Fx.

Package version
2.0.0-beta.7
Category
Generator composition
Since
1.0.0

Follow one execution

Run the Effect once per subscription and flatten the Fx it returns.

Fx timelineunwrap(setup)unwrap
Operatorunwrap(setup)
Read this diagram

Follow each lane from left to right. Events stacked vertically share a tick; the green cursor marks the current time across every lane.

  • A value
    The text inside the pill is the emitted value.
  • Work starts
    The raised chevron starts an inner run (^ in the source).
  • The run returns
    The vertical bar ends this lane’s run.
  • A cause is delivered
    The exclamation mark belongs to this lane.
  • Work is interrupted
    The cross marks cancellation of this run.
  • Current time
    The line and diamond move together across all lanes.
  • Happening now
    A highlighted event is at the current tick.
  • Still ahead
    Muted, dashed values have not happened yet.
  • Time continues
    The lane’s arrow is not a return marker. An empty stretch can be quiet work that is still running.

Illustrated ticks start at 0. At 1×, one illustrated tick takes one second; captions specify real durations when timing matters. A cause or interruption belongs to its lane, and other work may continue. Scroll horizontally to inspect the rest of a long timeline.

Acquisition and inner failures are forwarded and both environments remain in the returned type. unwrap does not create a Scope or hide one: interruption stops whichever phase is active, and any resourceful Effect or inner Fx must expose and receive its own Scope requirement.

Source implementation · Learn the surrounding model

Compare all Fx timelines →

Import

import { unwrap } from "@typed/fx/Fx";

Signatures

export declare const unwrap: <A = never, E = never, R = never, E2 = never, R2 = never>(effect: Effect.Effect<Fx<A, E, R>, E2, R2>) => Fx<A, E | E2, R | R2>;

Why

unwrap defers choosing or acquiring a producer until observation, while keeping the Effect and the selected Fx in one typed push pipeline.

Execution and cardinality

Each observation runs effect once. On success, the produced Fx is observed and all of its values are forwarded in order. The acquisition Effect itself emits no value, and the inner is never started if acquisition fails.

Ownership and lifetime

Acquisition and inner failures are forwarded and both environments remain in the returned type. unwrap does not create a Scope or hide one: interruption stops whichever phase is active, and any resourceful Effect or inner Fx must expose and receive its own Scope requirement.

Examples

import { Fx } from "@typed/fx"
import { Effect } from "effect"

const selected = Fx.unwrap(
  Effect.succeed(Fx.fromIterable(["ready", "running"]))
)

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source