{
  "id": "@typed/fx#Push.mapAccumEffect",
  "canonicalId": "@typed/fx/Push#mapAccumEffect",
  "symbol": {
    "id": "@typed/fx#Push.mapAccumEffect",
    "packageName": "@typed/fx",
    "moduleName": ".",
    "exportName": "Push.mapAccumEffect",
    "kind": "constant",
    "signatures": [
      "export declare const mapAccumEffect: {\n    <S, B, C, E3, R3>(initial: S, f: (s: S, b: B) => Effect.Effect<readonly [\n        S,\n        C\n    ], E3, R3>): <A, E, R, E2, R2>(push: Push<A, E, R, B, E2, R2>) => Push<A, E, R, C, E2 | E3, R2 | R3>;\n    <A, E, R, B, E2, R2, S, C, E3, R3>(push: Push<A, E, R, B, E2, R2>, initial: S, f: (s: S, b: B) => Effect.Effect<readonly [\n        S,\n        C\n    ], E3, R3>): Push<A, E, R, C, E2 | E3, R2 | R3>;\n};"
    ],
    "summary": "Maps over the output (Fx) side of a `Push` with an effectful accumulator: for each emitted value `b`,\nruns `f(state, b)` to get `[nextState, emitted]` and emits the second element.\nThe adapter does not serialize callbacks. Calling `onSuccess` invokes `f`\nimmediately with the current seed and constructs its Effect; overlapping calls\ncan therefore observe the same seed. Successful completion commits the returned\nseed and emits in completion order, so later completion may overwrite newer\nstate. Reducer failure is sent to the output Sink, emits nothing, restores that\ncall's previous seed, and completes normally so a continuing producer can send\nlater values. The input Sink is unchanged.",
    "sections": {
      "Why": "Use an effectful accumulator when each transition needs services or can fail,\nwhile keeping state local to observation rather than global application state.",
      "Ownership and lifetime": "Each output run owns one mutable seed, but concurrent producer callbacks may\nrace over it; callers needing serialized state transitions must serialize the\nupstream deliveries. Each callback fiber runs and interrupts its own reducer\nEffect. `E3` and `R3` join the output channels. State is discarded when the\nsubscription ends."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport * as Fx from \"@typed/fx/Fx\"\nimport * as Push from \"@typed/fx/Push\"\nimport * as Sink from \"@typed/fx/Sink\"\n\nconst concurrent = Fx.make<number>((sink) =>\n  Effect.all([sink.onSuccess(1), sink.onSuccess(2)], {\n    concurrency: \"unbounded\",\n    discard: true\n  })\n)\nconst push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), concurrent)\nconst totals = Push.mapAccumEffect(push, 0, (seed, value) =>\n  Effect.sleep(value === 1 ? \"20 millis\" : \"1 millis\").pipe(\n    Effect.as([seed + value, seed + value] as const)\n  )\n)\nconst program = Fx.collectAll(totals).pipe(Effect.scoped)\n// Both reducers see seed 0; Effect.runPromise(program) resolves to [2, 1].\n\nconst values: Array<number> = []\nlet failures = 0\nconst sequential = Push.make(\n  Sink.make(() => Effect.void, (_: string) => Effect.void),\n  Fx.fromIterable([1, 2, 3])\n)\nconst continued = Push.mapAccumEffect(sequential, 0, (seed, value) =>\n  value === 2\n    ? Effect.fail(\"rejected\" as const)\n    : Effect.succeed([seed + value, seed + value] as const)\n)\nconst recovery = continued.run(Sink.make(\n  () => Effect.sync(() => { failures += 1 }),\n  (value) => Effect.sync(() => values.push(value))\n))\n// Effect.runPromise(recovery) leaves values [1, 4] and failures 1."
      }
    ],
    "relations": [],
    "source": {
      "file": "packages/fx/src/Push/Push.ts",
      "line": 2061
    },
    "since": "1.0.0",
    "category": "Stateful outputs"
  },
  "exposure": {
    "recordKind": "declaration",
    "id": "@typed/fx#Push.mapAccumEffect",
    "packageName": "@typed/fx",
    "packageVersion": "2.0.0-beta.7",
    "moduleName": ".",
    "consumerSpecifier": "@typed/fx",
    "exportName": "Push",
    "qualifiedName": "Push.mapAccumEffect",
    "declarationKey": "declaration:61325bf9aea2e95fb5003329",
    "family": "variable",
    "signatures": [
      "export declare const mapAccumEffect: {\n    <S, B, C, E3, R3>(initial: S, f: (s: S, b: B) => Effect.Effect<readonly [\n        S,\n        C\n    ], E3, R3>): <A, E, R, E2, R2>(push: Push<A, E, R, B, E2, R2>) => Push<A, E, R, C, E2 | E3, R2 | R3>;\n    <A, E, R, B, E2, R2, S, C, E3, R3>(push: Push<A, E, R, B, E2, R2>, initial: S, f: (s: S, b: B) => Effect.Effect<readonly [\n        S,\n        C\n    ], E3, R3>): Push<A, E, R, C, E2 | E3, R2 | R3>;\n};"
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Push/Push.ts",
        "start": {
          "line": 2061,
          "column": 14
        },
        "end": {
          "line": 2105,
          "column": 3
        }
      },
      {
        "file": "packages/fx/src/Push/Push.ts",
        "start": {
          "line": 2062,
          "column": 3
        },
        "end": {
          "line": 2065,
          "column": 94
        }
      },
      {
        "file": "packages/fx/src/Push/Push.ts",
        "start": {
          "line": 2066,
          "column": 3
        },
        "end": {
          "line": 2070,
          "column": 41
        }
      }
    ],
    "aliases": [
      "@typed/fx/Push#mapAccumEffect"
    ],
    "isAlias": true,
    "parentId": "@typed/fx#Push",
    "static": false,
    "importedFrom": "declaration:61325bf9aea2e95fb5003329"
  },
  "declaration": {
    "declarationKey": "declaration:61325bf9aea2e95fb5003329",
    "name": "mapAccumEffect",
    "family": "variable",
    "facets": [
      {
        "family": "variable",
        "syntaxKind": "VariableDeclaration",
        "signatures": [
          "export declare const mapAccumEffect: {\n    <S, B, C, E3, R3>(initial: S, f: (s: S, b: B) => Effect.Effect<readonly [\n        S,\n        C\n    ], E3, R3>): <A, E, R, E2, R2>(push: Push<A, E, R, B, E2, R2>) => Push<A, E, R, C, E2 | E3, R2 | R3>;\n    <A, E, R, B, E2, R2, S, C, E3, R3>(push: Push<A, E, R, B, E2, R2>, initial: S, f: (s: S, b: B) => Effect.Effect<readonly [\n        S,\n        C\n    ], E3, R3>): Push<A, E, R, C, E2 | E3, R2 | R3>;\n};"
        ],
        "typeParameters": [],
        "sourceSpans": [
          {
            "file": "packages/fx/src/Push/Push.ts",
            "start": {
              "line": 2061,
              "column": 14
            },
            "end": {
              "line": 2105,
              "column": 3
            }
          }
        ],
        "static": false,
        "readonly": false,
        "optional": false
      },
      {
        "family": "call-signature",
        "syntaxKind": "CallSignature",
        "signatures": [
          "<S, B, C, E3, R3>(initial: S, f: (s: S, b: B) => Effect.Effect<readonly [\n    S,\n    C\n], E3, R3>): <A, E, R, E2, R2>(push: Push<A, E, R, B, E2, R2>) => Push<A, E, R, C, E2 | E3, R2 | R3>;",
          "<A, E, R, B, E2, R2, S, C, E3, R3>(push: Push<A, E, R, B, E2, R2>, initial: S, f: (s: S, b: B) => Effect.Effect<readonly [\n    S,\n    C\n], E3, R3>): Push<A, E, R, C, E2 | E3, R2 | R3>;"
        ],
        "typeParameters": [
          "S",
          "B",
          "C",
          "E3",
          "R3",
          "A",
          "E",
          "R",
          "E2",
          "R2"
        ],
        "sourceSpans": [
          {
            "file": "packages/fx/src/Push/Push.ts",
            "start": {
              "line": 2062,
              "column": 3
            },
            "end": {
              "line": 2065,
              "column": 94
            }
          },
          {
            "file": "packages/fx/src/Push/Push.ts",
            "start": {
              "line": 2066,
              "column": 3
            },
            "end": {
              "line": 2070,
              "column": 41
            }
          }
        ],
        "static": false,
        "readonly": false,
        "optional": false
      }
    ],
    "signatures": [
      "export declare const mapAccumEffect: {\n    <S, B, C, E3, R3>(initial: S, f: (s: S, b: B) => Effect.Effect<readonly [\n        S,\n        C\n    ], E3, R3>): <A, E, R, E2, R2>(push: Push<A, E, R, B, E2, R2>) => Push<A, E, R, C, E2 | E3, R2 | R3>;\n    <A, E, R, B, E2, R2, S, C, E3, R3>(push: Push<A, E, R, B, E2, R2>, initial: S, f: (s: S, b: B) => Effect.Effect<readonly [\n        S,\n        C\n    ], E3, R3>): Push<A, E, R, C, E2 | E3, R2 | R3>;\n};"
    ],
    "typeParameters": [
      "S",
      "B",
      "C",
      "E3",
      "R3",
      "A",
      "E",
      "R",
      "E2",
      "R2"
    ],
    "summary": "Maps over the output (Fx) side of a `Push` with an effectful accumulator: for each emitted value `b`,\nruns `f(state, b)` to get `[nextState, emitted]` and emits the second element.\nThe adapter does not serialize callbacks. Calling `onSuccess` invokes `f`\nimmediately with the current seed and constructs its Effect; overlapping calls\ncan therefore observe the same seed. Successful completion commits the returned\nseed and emits in completion order, so later completion may overwrite newer\nstate. Reducer failure is sent to the output Sink, emits nothing, restores that\ncall's previous seed, and completes normally so a continuing producer can send\nlater values. The input Sink is unchanged.",
    "sections": {
      "Why": "Use an effectful accumulator when each transition needs services or can fail,\nwhile keeping state local to observation rather than global application state.",
      "Ownership and lifetime": "Each output run owns one mutable seed, but concurrent producer callbacks may\nrace over it; callers needing serialized state transitions must serialize the\nupstream deliveries. Each callback fiber runs and interrupts its own reducer\nEffect. `E3` and `R3` join the output channels. State is discarded when the\nsubscription ends."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport * as Fx from \"@typed/fx/Fx\"\nimport * as Push from \"@typed/fx/Push\"\nimport * as Sink from \"@typed/fx/Sink\"\n\nconst concurrent = Fx.make<number>((sink) =>\n  Effect.all([sink.onSuccess(1), sink.onSuccess(2)], {\n    concurrency: \"unbounded\",\n    discard: true\n  })\n)\nconst push = Push.make(Sink.make(() => Effect.void, (_: string) => Effect.void), concurrent)\nconst totals = Push.mapAccumEffect(push, 0, (seed, value) =>\n  Effect.sleep(value === 1 ? \"20 millis\" : \"1 millis\").pipe(\n    Effect.as([seed + value, seed + value] as const)\n  )\n)\nconst program = Fx.collectAll(totals).pipe(Effect.scoped)\n// Both reducers see seed 0; Effect.runPromise(program) resolves to [2, 1].\n\nconst values: Array<number> = []\nlet failures = 0\nconst sequential = Push.make(\n  Sink.make(() => Effect.void, (_: string) => Effect.void),\n  Fx.fromIterable([1, 2, 3])\n)\nconst continued = Push.mapAccumEffect(sequential, 0, (seed, value) =>\n  value === 2\n    ? Effect.fail(\"rejected\" as const)\n    : Effect.succeed([seed + value, seed + value] as const)\n)\nconst recovery = continued.run(Sink.make(\n  () => Effect.sync(() => { failures += 1 }),\n  (value) => Effect.sync(() => values.push(value))\n))\n// Effect.runPromise(recovery) leaves values [1, 4] and failures 1."
      }
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Push/Push.ts",
        "start": {
          "line": 2061,
          "column": 14
        },
        "end": {
          "line": 2105,
          "column": 3
        }
      },
      {
        "file": "packages/fx/src/Push/Push.ts",
        "start": {
          "line": 2062,
          "column": 3
        },
        "end": {
          "line": 2065,
          "column": 94
        }
      },
      {
        "file": "packages/fx/src/Push/Push.ts",
        "start": {
          "line": 2066,
          "column": 3
        },
        "end": {
          "line": 2070,
          "column": 41
        }
      }
    ],
    "since": "1.0.0",
    "category": "Stateful outputs"
  }
}
