Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ZTransducer#collectAllN pulls too much data #3559

@simpadjo

Description

@simpadjo

Testcase:

//crashes
Stream(1,2,3) ++ Stream.fail("X")).transduce(ZTransducer.collectAllN(3)).take(1).runCollect

Why it happens:
collectAllN relies on foldWeightedDecompose.
When weight reaches 3, it doesn't emit an element immediately but rather waits until weight becomes strictly bigger.
I tried to change foldWeightedDecompose to terminate earlier but it breaks collectAllSetN.

Why it is important:
I'm working on Transducer#race family of combinators.
Racing transducers in the presence of chunking could lead to very surprising results.
When a single transducer emits at unexpected moment, this makes things even worse.

It could be fixed by adding a flag to foldWeightedDecompose whether it should terminate early.
Or alternatively, by stopping digging the hole and implementing collectAllN separately.

@iravid WDYT?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions