Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stream#chunkAll #1855

Merged
merged 2 commits into from
Apr 26, 2020
Merged

Add Stream#chunkAll #1855

merged 2 commits into from
Apr 26, 2020

Conversation

mpilquist
Copy link
Member

@mpilquist mpilquist commented Apr 24, 2020

Fixes #1834

def chunkAll: Stream[F, Chunk[O]] = {
def loop(s: Stream[F, O], acc: Chunk.Queue[O]): Pull[F, Chunk[O], Unit] =
s.pull.uncons.flatMap {
case Some((hd, tl)) => loop(tl, acc :+ hd)
Copy link
Contributor

@diesalbla diesalbla Apr 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions here:

  1. Would we gain something if we were to get the chunks from the original s.pull, and iterate and append chunk by chunk, rather than element-by-element?
  2. Would we benefit from having a mutable constructor of an immutable chunk, much in the same way as Scala collections have mutable builders for then-immutable structures (e.g. ListBuffer for List)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this implementation does both already more or less. We're pulling full chunks from the source (via uncons, not uncons1) and we're appending those chunks to a Chunk.Queue, which preserves them as whole chunks during the building phase. Only when toChunk is called on that queue are they all concatenated in to a single chunk.

@SystemFw SystemFw merged commit 64bd9af into typelevel:master Apr 26, 2020
@mpilquist mpilquist added this to the 2.4.0 milestone Jun 8, 2020
@mpilquist mpilquist deleted the topic/chunkAll branch February 18, 2024 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add chunkAll
3 participants