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 ChunkBuilder#isEmpty method #8805

Open
wants to merge 2 commits into
base: series/2.x
Choose a base branch
from

Conversation

kyri-petrou
Copy link
Contributor

Being able to know whether the ChunkBuilder currently contains any elements can be quite useful in some cases, e.g.,

def collectFooAndBar(): ChunkBuilder[String] = {
  val builder1 = new ChunkBuilder.Obj[String]
  val builder2 = new ChunkBuilder.Obj[String]

  foo(builder1)
  bar(builder2)
  
  if (builder1.isEmpty) builder2
  else if (builder2.isEmpty) builder1
  else builder1 ++= builder2.result() 
}

Note that MiMa didn't like me adding an abstract method on ChunkBuilder (even though it's a sealed abstract class, and just to play it safe I added another final class extension to ChunkBuilder, and only the final classes have the isEmpty method. Let me know if you think it's okay to add the abstract method and I'll do that

@kyri-petrou kyri-petrou changed the title Add ChunkBuilder#isEmpty method Add ChunkBuilder#isEmpty method Apr 30, 2024
def result(): Chunk[SShort] =
Chunk.fromArray(arrayBuilder.result())
override def sizeHint(n: SInt): Unit =
arrayBuilder.sizeHint(n)
override def toString: String =
"ChunkBuilder.Short"
}

final class Obj[A] extends ChunkBuilder[A] {
Copy link
Member

@guizmaii guizmaii May 3, 2024

Choose a reason for hiding this comment

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

Why did you choose Obj as the name for this class? Why not something like ChunkBuilderLive for example? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly because it's meant for objects (i.e., non-primitives). But yeah Obj doesn't sound too great. We could go with a similar name as ArrayBuilder and use OfRef

Copy link
Member

Choose a reason for hiding this comment

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

Oh ok I understand now. Thanks! I let you choose what you prefer :)

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.

None yet

2 participants