effect icon indicating copy to clipboard operation
effect copied to clipboard

foldWeightedDecompose example in docs is not working.

Open LumaKernel opened this issue 6 months ago • 0 comments

What version of Effect is running?

latest (3.16.8)

What steps can reproduce the bug?

This is the short tiny script:

https://effect.website/play/#a032c0efed18

import { Sink, Stream, Effect, Console, Chunk, pipe } from "effect";

pipe(
  Stream.make(1, 5, 1),
  Stream.transduce(
    Sink.foldWeightedDecompose({
      initial: Chunk.empty<number>(),
      maxCost: 4,
      cost: (acc) =>
        pipe(
          acc,
          Chunk.reduce(0, (x, y) => x + y),
        ),
      decompose: (n) => Chunk.make(n - 1, 1),
      body: (acc, el) => pipe(acc, Chunk.append(el)),
    }),
  ),
  Stream.runCollect,
  Effect.andThen(Chunk.toArray),
  Effect.andThen(Console.log),
  Effect.runPromiseExit,
);

Just run this with bun/tsx/anything and you can see it's stuck and nothing will be shown.

This is just referring to https://effect-ts.github.io/effect/effect/Sink.ts.html#foldweighteddecompose .

I also tried to Stream.tap(Console.log), , but it doesn't show anything.

What is the expected behavior?

The example https://effect-ts.github.io/effect/effect/Sink.ts.html#foldweighteddecompose is working. Not sure about the exact behavior because just to know that, I tried this.

What do you see instead?

nothing, and it seems stuck.

Additional information

Note that I fixed these points when pasting example:

  • foldWeightedDecompose seems just accepting object style input (at least type level).
  • cost function is getting number, but should get Chunk.

LumaKernel avatar Jun 19 '25 02:06 LumaKernel