To iterate over a set in Go, you can use the range keyword.
In this example,
package main
import (
"fmt"
"github.com/deckarep/golang-set"
)
func main() {
// Define set
mySet := mapset.NewSet()
mySet.Add(1)
mySet.Add(2)
mySet.Add(3)
// Iterate over set using range keyword
for item := range mySet.Iterator().C {
fmt.Println(item)
}
}
1 2 3
In this tutorial, we learned How to Iterate Over a Set in Go language with well detailed examples.