{
  "id": "@typed/fx#Sink.withState",
  "canonicalId": "@typed/fx/Sink#withState",
  "symbol": {
    "id": "@typed/fx#Sink.withState",
    "packageName": "@typed/fx",
    "moduleName": ".",
    "exportName": "Sink.withState",
    "kind": "function",
    "signatures": [
      "export declare function withState<A, E, R, B, R2>(sink: Sink<A, E, R>, state: B, f: (sink: Sink.WithState<A, E, R, B>, params: {\n    signal: AbortSignal;\n    scheduler: Scheduler;\n}) => Effect.Effect<unknown, never, R2>): Effect.Effect<void, never, R | R2>;"
    ],
    "summary": "Runs a callback with an early-exit sink and a private Effect `Ref` initialized to `state`.",
    "sections": {
      "Why": "It supports stateful consumer protocols while keeping their state local to one run.",
      "Ownership and lifetime": "Each execution creates one Ref and owns it until exit or interruption. Ref operations are lazy\natomic Effects: serialized callback execution preserves producer order, while concurrent execution\nis ordered by scheduling. No state is shared across `withState` executions."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Effect, Ref } from \"effect\"\nimport * as Sink from \"@typed/fx/Sink\"\nconst base = Sink.make(Effect.logError, Effect.log)\nconst program = Sink.withState(base, 0, ({ state, earlyExit }) => Ref.set(state, 1).pipe(Effect.andThen(earlyExit)))"
      }
    ],
    "relations": [],
    "source": {
      "file": "packages/fx/src/Sink/combinators.ts",
      "line": 394
    },
    "since": "1.0.0",
    "category": "Stateful delivery"
  },
  "exposure": {
    "recordKind": "declaration",
    "id": "@typed/fx#Sink.withState",
    "packageName": "@typed/fx",
    "packageVersion": "2.0.0-beta.13",
    "moduleName": ".",
    "consumerSpecifier": "@typed/fx",
    "exportName": "Sink",
    "qualifiedName": "Sink.withState",
    "declarationKey": "declaration:4c57f8fb17c6d51e42322f5b",
    "family": "function",
    "signatures": [
      "export declare function withState<A, E, R, B, R2>(sink: Sink<A, E, R>, state: B, f: (sink: Sink.WithState<A, E, R, B>, params: {\n    signal: AbortSignal;\n    scheduler: Scheduler;\n}) => Effect.Effect<unknown, never, R2>): Effect.Effect<void, never, R | R2>;"
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Sink/combinators.ts",
        "start": {
          "line": 394,
          "column": 1
        },
        "end": {
          "line": 405,
          "column": 2
        }
      }
    ],
    "aliases": [
      "@typed/fx/Sink#withState"
    ],
    "isAlias": true,
    "parentId": "@typed/fx#Sink",
    "static": false,
    "importedFrom": "declaration:4c57f8fb17c6d51e42322f5b"
  },
  "declaration": {
    "declarationKey": "declaration:4c57f8fb17c6d51e42322f5b",
    "name": "withState",
    "family": "function",
    "facets": [
      {
        "family": "function",
        "syntaxKind": "FunctionDeclaration",
        "signatures": [
          "export declare function withState<A, E, R, B, R2>(sink: Sink<A, E, R>, state: B, f: (sink: Sink.WithState<A, E, R, B>, params: {\n    signal: AbortSignal;\n    scheduler: Scheduler;\n}) => Effect.Effect<unknown, never, R2>): Effect.Effect<void, never, R | R2>;"
        ],
        "typeParameters": [
          "A",
          "E",
          "R",
          "B",
          "R2"
        ],
        "sourceSpans": [
          {
            "file": "packages/fx/src/Sink/combinators.ts",
            "start": {
              "line": 394,
              "column": 1
            },
            "end": {
              "line": 405,
              "column": 2
            }
          }
        ],
        "static": false,
        "readonly": false,
        "optional": false
      }
    ],
    "signatures": [
      "export declare function withState<A, E, R, B, R2>(sink: Sink<A, E, R>, state: B, f: (sink: Sink.WithState<A, E, R, B>, params: {\n    signal: AbortSignal;\n    scheduler: Scheduler;\n}) => Effect.Effect<unknown, never, R2>): Effect.Effect<void, never, R | R2>;"
    ],
    "typeParameters": [
      "A",
      "E",
      "R",
      "B",
      "R2"
    ],
    "summary": "Runs a callback with an early-exit sink and a private Effect `Ref` initialized to `state`.",
    "sections": {
      "Why": "It supports stateful consumer protocols while keeping their state local to one run.",
      "Ownership and lifetime": "Each execution creates one Ref and owns it until exit or interruption. Ref operations are lazy\natomic Effects: serialized callback execution preserves producer order, while concurrent execution\nis ordered by scheduling. No state is shared across `withState` executions."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Effect, Ref } from \"effect\"\nimport * as Sink from \"@typed/fx/Sink\"\nconst base = Sink.make(Effect.logError, Effect.log)\nconst program = Sink.withState(base, 0, ({ state, earlyExit }) => Ref.set(state, 1).pipe(Effect.andThen(earlyExit)))"
      }
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Sink/combinators.ts",
        "start": {
          "line": 394,
          "column": 1
        },
        "end": {
          "line": 405,
          "column": 2
        }
      }
    ],
    "since": "1.0.0",
    "category": "Stateful delivery"
  }
}
