{
  "id": "@typed/fx/Fx#switchMapEffect",
  "canonicalId": "@typed/fx/Fx#switchMapEffect",
  "symbol": {
    "id": "@typed/fx/Fx#switchMapEffect",
    "packageName": "@typed/fx",
    "moduleName": "Fx",
    "exportName": "switchMapEffect",
    "kind": "constant",
    "signatures": [
      "export declare const switchMapEffect: FlatMapEffectLike;"
    ],
    "summary": "Maps each element of an Fx to an Effect, and switches to the latest effect.\n\nWhen a new element is emitted, the previous effect is cancelled.",
    "sections": {
      "Why": "This is the Effect-producing form of {@link switchMap }. It makes latest-only\nEffect execution explicit without wrapping callbacks with `Fx.fromEffect`.",
      "Switching and cardinality": "Every source value creates one callback Effect. A new value interrupts and\nawaits the previous Effect before starting its replacement. Each Effect can\nemit one successful result, but an interrupted Effect may emit none.",
      "Ownership and lifetime": "Source and current callback failures remain typed and callback services are\nadded to requirements. The required `Scope` owns the current Effect. Source\ncompletion waits for it; replacement and output interruption run its\nfinalizers before relinquishing the lifetime."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Fx } from \"@typed/fx\"\nimport { Effect } from \"effect\"\n\nconst queries = Fx.mergeAll(\n  Fx.at(\"a\", \"0 millis\"),\n  Fx.at(\"ab\", \"5 millis\")\n)\nconst result = Fx.switchMapEffect(queries, (query) =>\n  Effect.as(Effect.sleep(\"20 millis\"), query).pipe(\n    Effect.ensuring(Effect.log(`${query} closed`))\n  )\n)\nEffect.runPromise(Effect.scoped(Fx.collectAll(result))).then(console.log)\n// [\"ab\"]"
      }
    ],
    "relations": [],
    "source": {
      "file": "packages/fx/src/Fx/combinators/switchMapEffect.ts",
      "line": 56
    },
    "since": "1.0.0",
    "category": "Concurrent work"
  },
  "exposure": {
    "recordKind": "declaration",
    "id": "@typed/fx/Fx#switchMapEffect",
    "packageName": "@typed/fx",
    "packageVersion": "2.0.0-beta.13",
    "moduleName": "Fx",
    "consumerSpecifier": "@typed/fx/Fx",
    "exportName": "switchMapEffect",
    "qualifiedName": "switchMapEffect",
    "declarationKey": "declaration:7d707c911e76ac6503181eb6",
    "family": "variable",
    "signatures": [
      "export declare const switchMapEffect: FlatMapEffectLike;"
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Fx/combinators/switchMapEffect.ts",
        "start": {
          "line": 56,
          "column": 14
        },
        "end": {
          "line": 62,
          "column": 2
        }
      }
    ],
    "aliases": [
      "@typed/fx#Fx.switchMapEffect"
    ],
    "isAlias": false,
    "static": false
  },
  "declaration": {
    "declarationKey": "declaration:7d707c911e76ac6503181eb6",
    "name": "switchMapEffect",
    "family": "variable",
    "facets": [
      {
        "family": "variable",
        "syntaxKind": "VariableDeclaration",
        "signatures": [
          "export declare const switchMapEffect: FlatMapEffectLike;"
        ],
        "typeParameters": [],
        "sourceSpans": [
          {
            "file": "packages/fx/src/Fx/combinators/switchMapEffect.ts",
            "start": {
              "line": 56,
              "column": 14
            },
            "end": {
              "line": 62,
              "column": 2
            }
          }
        ],
        "static": false,
        "readonly": false,
        "optional": false
      }
    ],
    "signatures": [
      "export declare const switchMapEffect: FlatMapEffectLike;"
    ],
    "typeParameters": [],
    "summary": "Maps each element of an Fx to an Effect, and switches to the latest effect.\n\nWhen a new element is emitted, the previous effect is cancelled.",
    "sections": {
      "Why": "This is the Effect-producing form of {@link switchMap }. It makes latest-only\nEffect execution explicit without wrapping callbacks with `Fx.fromEffect`.",
      "Switching and cardinality": "Every source value creates one callback Effect. A new value interrupts and\nawaits the previous Effect before starting its replacement. Each Effect can\nemit one successful result, but an interrupted Effect may emit none.",
      "Ownership and lifetime": "Source and current callback failures remain typed and callback services are\nadded to requirements. The required `Scope` owns the current Effect. Source\ncompletion waits for it; replacement and output interruption run its\nfinalizers before relinquishing the lifetime."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Fx } from \"@typed/fx\"\nimport { Effect } from \"effect\"\n\nconst queries = Fx.mergeAll(\n  Fx.at(\"a\", \"0 millis\"),\n  Fx.at(\"ab\", \"5 millis\")\n)\nconst result = Fx.switchMapEffect(queries, (query) =>\n  Effect.as(Effect.sleep(\"20 millis\"), query).pipe(\n    Effect.ensuring(Effect.log(`${query} closed`))\n  )\n)\nEffect.runPromise(Effect.scoped(Fx.collectAll(result))).then(console.log)\n// [\"ab\"]"
      }
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Fx/combinators/switchMapEffect.ts",
        "start": {
          "line": 56,
          "column": 14
        },
        "end": {
          "line": 62,
          "column": 2
        }
      }
    ],
    "since": "1.0.0",
    "category": "Concurrent work"
  }
}
