variable / @typed/fx/Fx

concatMapEffect

Maps each element to an Effect and concatenates the results sequentially.

Package version
2.0.0-beta.7
Category
Concurrent work
Since
1.0.0

Follow one execution

One Effect runs at a time. Every successful Effect emits exactly one result in source order. This scenario uses concurrent source deliveries: a pending source callback can wait for admission while another callback is already active.

Fx timelineconcatMapEffect(save)concatMapEffect
OperatorconcatMapEffect(save)
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.

Source failures and Effect failures remain typed; callback services are added to the output requirements. The returned Fx requires Scope, which owns the active callback Effect and interrupts it when observation ends.

Source implementation · Learn the surrounding model

Compare all Fx timelines →

Import

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

Signatures

export declare const concatMapEffect: FlatMapEffectLike;

Why

This is the Effect-producing form of {@link concatMap}. It makes serialized commands explicit without requiring callers to wrap each Effect with Fx.fromEffect.

Ordering and cardinality

Each source value starts one Effect only after the previous Effect has completed. Each successful Effect emits exactly one value, so output order is source order and there is no overlap or buffering of successful results.

Ownership and lifetime

Source failures and Effect failures remain typed; callback services are added to the output requirements. The returned Fx requires Scope, which owns the active callback Effect and interrupts it when observation ends.

Examples

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

const saved = Fx.concatMapEffect(Fx.fromIterable([
  { id: "first", wait: "20 millis" as const },
  { id: "second", wait: "1 millis" as const }
]), ({ id, wait }) => Effect.as(Effect.sleep(wait), id))

const program = Effect.scoped(Fx.collectAll(saved))
Effect.runPromise(program).then(console.log)
// ["first", "second"]

Other public imports

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

Source