func Swap[T any](a, b *T) {
*a, *b = *b, *a
}
func main() {
a, b := 1, 2
fmt.Println(a, b)
Swap(&a, &b)
fmt.Println(a, b)
c, d := []int{1, 2, 3}, []int{4, 5, 6}
fmt.Println(c, d)
Swap(&c, &d)
fmt.Println(c, d)
e, f := &a, &b
fmt.Println(*e, *f)
Swap(&e, &f)
fmt.Println(*e, *f)
}
ch1, ch2 := make(chan int), make(chan int)
go func() {
for v1 := range ch1 {
fmt.Println("v1", v1)
}
}()
go func() {
for v2 := range ch2 {
fmt.Println("v2", v2)
}
}()
go func() {
for i := 0; ; i++ {
ch1 <- i
ch2 <- i * 10000
time.Sleep(time.Second)
}
}()
time.Sleep(time.Second * 5)
Swap(&ch1, &ch2)