--- /dev/null
+// You can edit this code!
+// Click here and start typing.
+package main
+
+import (
+ "fmt"
+ "math/rand"
+ "time"
+)
+
+type tuple struct {
+ a interface{}
+ b interface{}
+}
+
+func fanIn(ca, cb <-chan interface{}) <-chan tuple {
+ c := make(chan tuple)
+
+ go func() {
+ for {
+ var a, b interface{}
+ select {
+ case a = <-ca:
+ b = <-cb
+ case b = <-cb:
+ a = <-ca
+ }
+ c <- tuple{a: a, b: b}
+ }
+ }()
+
+ return c
+}
+
+func gen(c chan<- interface{}, t int) {
+ i := 0
+ for {
+ c <- i
+ i += 1
+ time.Sleep(time.Duration(t) * time.Second)
+ }
+}
+
+func main() {
+ a := make(chan interface{})
+ b := make(chan interface{})
+
+ i := 0
+ go gen(a, rand.Intn(5))
+ go gen(b, rand.Intn(5))
+ c := fanIn(a, b)
+ for i < 7 {
+ /*x := <-a
+ y := <-b*/
+ t := <- c
+ fmt.Println(t.a.(int), t.b.(int))
+ i += 1
+ }
+
+}
+