deckarep / golang-set

A simple, battle-tested and generic set type for the Go language. Trusted by Docker, 1Password, Ethereum and Hashicorp.
Other
4.15k stars 274 forks source link

What about adding a `set.Append(vals...T)` method to add multiple values to an existing set? #92

Closed jeffwidman closed 1 year ago

jeffwidman commented 2 years ago

We've got NewSet(vals...T) for creating a set from multiple values.

But today I found myself wanting to add a slice of objects to an existing set... today I have to write a for loop to range over the objects.

What about adding an append(vals... T) method... similar to Python, which allows adding multiple objects.

Alternatively Add(val T) bool could be modified to take multiple args, which would keep the API surface small. But it's a little undefined that it returns a bool... for multiple objects would that return true if all the objects got added to the existing set, or if at least one object got added?

Thoughts?

deckarep commented 2 years ago

I definitely support having some improved ergonomics like an Append api call. Maybe we can leave Add as is and go with this?

Sounds like a plan.