github.com/enetx/g@v1.0.80/examples/iter/iter_permutations.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/enetx/g" 7 ) 8 9 func main() { 10 // Create a slice of integers 11 slice := g.Slice[int]{1, 2, 3} 12 13 // Get an iterator for the slice, generate permutations, and collect the result 14 perms := slice.Iter().Permutations().Collect() 15 16 // Iterate over the permutations and print each one 17 for _, perm := range perms { 18 fmt.Println(perm) 19 } 20 21 // Create two slices of strings 22 p1 := g.SliceOf[g.String]("bbb", "ddd") 23 p2 := g.SliceOf[g.String]("xxx", "aaa") 24 25 // Chain the two slices, convert to uppercase, generate permutations, and collect the result 26 pp := p1. 27 Iter(). 28 Chain(p2.Iter()). 29 Map(g.String.Upper). 30 Permutations(). 31 Collect() 32 33 // Iterate over the permutations and print each one 34 for _, v := range pp { 35 v.Print() 36 } 37 }