hashicorp / go-set

The go-set package provides generic Set implementations for Go, including HashSet for types with a Hash() function and TreeSet for orderable data
Mozilla Public License 2.0
118 stars 8 forks source link

v3: implement Items() method for use with range keyword #91

Closed shoenig closed 2 months ago

shoenig commented 2 months ago

Starting with go1.23, Go supports using range with custom user types that satisfy interfaces of the iter package. We can make use of this functionality for iterating over elements of each type of set.

s := set.From([]int{2, 1, 1, 3})
for item := range s.Items() {
  fmt.Println(item)
}

This functionality replaces the need for the ForEach defined on each set type, and so that method is removed. This means we need a v3 breaking change for the release.

Closes #82 Part of #90