// Iterate over a set of ints and compute the sum of its elements. func Example() { s := set.EmptySet() for i := 1; i < 6; i++ { s.Add(i) } sum := 0 for v := range s.Iter() { val := v.(int) sum += val } fmt.Println(sum) // Output: 15 }
// Iterate over a set using the Apply function, checks if there is an element // that is even. func ExampleApply() { s := set.EmptySet() for i := 1; i < 20; i += 2 { s.Add(i) } s.Add(2) even := false f := func(v set.SetValue) bool { val := v.(int) if val%2 == 0 { even = true return false } return true } s.Apply(f) fmt.Println(even) // Output: true }