deckarep / golang-set

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

Add Sorted method #127

Closed Frassle closed 7 months ago

Frassle commented 9 months ago

This is a set variant on slices.Sort that makes it easy to get a sorted slice. This makes it easy to get the elements of the set into a sorted slice. Quite handy when using sets to build up unique elements but then needing a well defined iteration order.

Frassle commented 9 months ago

A helpful wrapper around https://pkg.go.dev/slices@go1.21.1#Sort. I could add SortedFunc as well if wanted to wrap https://pkg.go.dev/slices@go1.21.1#SortFunc.

deckarep commented 9 months ago

@Frassle - thanks for your contribution. This seems like a nice and convenient helper func. I’ll look it over in detail along with your other posted issue likely tomorrow.

Thanks for your interest and contribution!

Frassle commented 9 months ago

Noticed from your CI run that "slices" and "cmp" are only in go 1.21 so I've moved this to a new file that can be conditional by version. Won't break existing users, but anyone wanting to use sorted will need to be on 1.21.

Frassle commented 7 months ago

Hey @deckarep just to check in if you've had a chance to consider this yet?

deckarep commented 7 months ago

Thanks @Frassle for this change. Sorry I never got around to it but it looks good. Thanks @funwithbots for the pair of eyes.

This will show up in release: v2.5.0

Frassle commented 7 months ago

Thanks! And no worries about the time, I know how easy it is to lose track of things like this.