Python’s itertools maps to small loops plus slices and maps (Go 1.21+), sometimes container/ring.
a := []int{1, 2}
b := []int{3, 4}
out := append(append([]int{}, a...), b...)
func uniqSorted(xs []int) []int {
if len(xs) == 0 {
return xs
}
out := xs[:1]
for _, v := range xs[1:] {
if v != out[len(out)-1] {
out = append(out, v)
}
}
return out
}
Nested for loops; count known dimensions explicitly.
Implement recursively or use a focused library if combinatorics grow complex.
slices.Chunk (Go 1.23+)Batch elements for processing windows.
for i := 0; i < len(a) && i < len(b); i++ {
_, _ = a[i], b[i]
}
Different lengths need a policy (truncate, error, pad).
Channels or stateful iterator structs; avoid goroutines unless you need concurrency.