blob: 1515088c272335a87f6377b21651a29a68a74559 [file] [log] [blame]
// +build ignore,OMIT
package main
import (
"fmt"
"reflect"
)
func sendSlice(slice interface{}) (channel interface{}) {
sliceValue := reflect.ValueOf(slice)
chanType := reflect.ChanOf(reflect.BothDir, sliceValue.Type().Elem())
chanValue := reflect.MakeChan(chanType, 0)
go func() {
for i := 0; i < sliceValue.Len(); i++ {
chanValue.Send(sliceValue.Index(i))
}
chanValue.Close()
}()
return chanValue.Interface()
}
func main() {
ch := sendSlice([]int{1, 2, 3, 4, 5}).(chan int)
for v := range ch {
fmt.Println(v)
}
}