{
  "id": "@typed/fx/Fx#switchMap",
  "canonicalId": "@typed/fx/Fx#switchMap",
  "symbol": {
    "id": "@typed/fx/Fx#switchMap",
    "packageName": "@typed/fx",
    "moduleName": "Fx",
    "exportName": "switchMap",
    "kind": "constant",
    "signatures": [
      "export declare const switchMap: FlatMapLike;"
    ],
    "summary": "Maps each element of an Fx to a new Fx, and switches to the latest inner Fx.\n\nWhen a new element is emitted, the previous inner Fx is cancelled.",
    "sections": {
      "Why": "`switchMap` models work whose result becomes obsolete when a newer source\nvalue arrives, such as suggestions for the current query. Cancellation is the\npolicy: obsolete work is not allowed to finish in the background.",
      "Switching, ordering, and cardinality": "Every source value calls `f`. Before the new inner starts, the previous inner\nis interrupted and its interruption is awaited. Only the latest inner remains\nactive; values it emitted before replacement remain visible, while later\nvalues from the replaced inner are suppressed. There is no result buffer.",
      "Ownership and lifetime": "Source and current-inner failures are forwarded and their services remain\ntyped. The returned Fx requires `Scope`, which owns the current inner fiber.\nSource completion waits for the latest inner. Replacing or interrupting the\noutput closes obsolete inner work and runs its scoped finalizers before the\nreplacement proceeds."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Fx } from \"@typed/fx\"\nimport { Effect } from \"effect\"\n\nconst queries = Fx.mergeAll(\n  Fx.at(\"typed\", \"0 millis\"),\n  Fx.at(\"typed fx\", \"5 millis\")\n)\nconst suggestions = Fx.switchMap(queries, (query) =>\n  Fx.ensuring(Fx.at(query, \"20 millis\"), Effect.log(`${query} closed`))\n)\nEffect.runPromise(Effect.scoped(Fx.collectAll(suggestions))).then(console.log)\n// logs cleanup for \"typed\" and resolves [\"typed fx\"]"
      }
    ],
    "relations": [],
    "source": {
      "file": "packages/fx/src/Fx/combinators/switchMap.ts",
      "line": 61
    },
    "since": "1.0.0",
    "category": "Concurrent work"
  },
  "exposure": {
    "recordKind": "declaration",
    "id": "@typed/fx/Fx#switchMap",
    "packageName": "@typed/fx",
    "packageVersion": "2.0.0-beta.13",
    "moduleName": "Fx",
    "consumerSpecifier": "@typed/fx/Fx",
    "exportName": "switchMap",
    "qualifiedName": "switchMap",
    "declarationKey": "declaration:f51f7727a8d5450407902f05",
    "family": "variable",
    "signatures": [
      "export declare const switchMap: FlatMapLike;"
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Fx/combinators/switchMap.ts",
        "start": {
          "line": 61,
          "column": 14
        },
        "end": {
          "line": 93,
          "column": 2
        }
      }
    ],
    "aliases": [
      "@typed/fx#Fx.switchMap"
    ],
    "isAlias": false,
    "static": false
  },
  "declaration": {
    "declarationKey": "declaration:f51f7727a8d5450407902f05",
    "name": "switchMap",
    "family": "variable",
    "facets": [
      {
        "family": "variable",
        "syntaxKind": "VariableDeclaration",
        "signatures": [
          "export declare const switchMap: FlatMapLike;"
        ],
        "typeParameters": [],
        "sourceSpans": [
          {
            "file": "packages/fx/src/Fx/combinators/switchMap.ts",
            "start": {
              "line": 61,
              "column": 14
            },
            "end": {
              "line": 93,
              "column": 2
            }
          }
        ],
        "static": false,
        "readonly": false,
        "optional": false
      }
    ],
    "signatures": [
      "export declare const switchMap: FlatMapLike;"
    ],
    "typeParameters": [],
    "summary": "Maps each element of an Fx to a new Fx, and switches to the latest inner Fx.\n\nWhen a new element is emitted, the previous inner Fx is cancelled.",
    "sections": {
      "Why": "`switchMap` models work whose result becomes obsolete when a newer source\nvalue arrives, such as suggestions for the current query. Cancellation is the\npolicy: obsolete work is not allowed to finish in the background.",
      "Switching, ordering, and cardinality": "Every source value calls `f`. Before the new inner starts, the previous inner\nis interrupted and its interruption is awaited. Only the latest inner remains\nactive; values it emitted before replacement remain visible, while later\nvalues from the replaced inner are suppressed. There is no result buffer.",
      "Ownership and lifetime": "Source and current-inner failures are forwarded and their services remain\ntyped. The returned Fx requires `Scope`, which owns the current inner fiber.\nSource completion waits for the latest inner. Replacing or interrupting the\noutput closes obsolete inner work and runs its scoped finalizers before the\nreplacement proceeds."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Fx } from \"@typed/fx\"\nimport { Effect } from \"effect\"\n\nconst queries = Fx.mergeAll(\n  Fx.at(\"typed\", \"0 millis\"),\n  Fx.at(\"typed fx\", \"5 millis\")\n)\nconst suggestions = Fx.switchMap(queries, (query) =>\n  Fx.ensuring(Fx.at(query, \"20 millis\"), Effect.log(`${query} closed`))\n)\nEffect.runPromise(Effect.scoped(Fx.collectAll(suggestions))).then(console.log)\n// logs cleanup for \"typed\" and resolves [\"typed fx\"]"
      }
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Fx/combinators/switchMap.ts",
        "start": {
          "line": 61,
          "column": 14
        },
        "end": {
          "line": 93,
          "column": 2
        }
      }
    ],
    "since": "1.0.0",
    "category": "Concurrent work"
  }
}
