From 2f186a719cb9cd6956c2f3990b12f53b932aea78 Mon Sep 17 00:00:00 2001 From: Nicoreia Date: Fri, 26 Jun 2026 22:38:06 +0200 Subject: [PATCH] docs: fix foldWeightedDecompose example to type-check and terminate The JSDoc example for `Sink.foldWeightedDecompose` used the old positional-argument API (hidden behind `skip-type-checking`) and a `decompose` function that never produced indivisible values, so the example failed to type-check and hung at runtime (reported in #5055). Rewrite it using the current object-style API and a terminating `decompose`, and drop `skip-type-checking` so docgen validates the example going forward. It still emits Chunk(1), Chunk(4), Chunk(1, 1). --- packages/effect/src/Sink.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/effect/src/Sink.ts b/packages/effect/src/Sink.ts index 61756be4b57..d11c7ad71f5 100644 --- a/packages/effect/src/Sink.ts +++ b/packages/effect/src/Sink.ts @@ -813,20 +813,23 @@ export const foldWeighted: ( * The `decompose` function will be used for decomposing elements that cause * an `S` aggregate to cross `max` into smaller elements. For example: * - * ```ts skip-type-checking - * pipe( - * Stream.make(1, 5, 1), - * Stream.transduce( - * Sink.foldWeightedDecompose( - * Chunk.empty(), - * 4, - * (n: number) => n, - * (n: number) => Chunk.make(n - 1, 1), - * (acc, el) => pipe(acc, Chunk.append(el)) - * ) - * ), + * ```ts + * import { Chunk, Effect, Sink, Stream } from "effect" + * + * const sink = Sink.foldWeightedDecompose({ + * initial: Chunk.empty(), + * maxCost: 4, + * cost: (_acc, n: number) => n, + * decompose: (n: number) => (n > 4 ? Chunk.make(4, n - 4) : Chunk.of(n)), + * body: (acc, n) => Chunk.append(acc, n) + * }) + * + * const program = Stream.make(1, 5, 1).pipe( + * Stream.transduce(sink), * Stream.runCollect * ) + * + * Effect.runPromise(program).then(console.log) * ``` * * The stream would emit the elements `Chunk(1), Chunk(4), Chunk(1, 1)`.