Is there, in Go, a more idiomatic way to add all the elements of an array/slice into a channel than the following?
ch := make(chan string)
values := []string {"lol", "cat", "lolcat"}
go func() {
for _,v := range values {
ch <- v
}
}()
I was looking for something like ch <- values...
(which is rejected by the compiler)
You can declare a chan of string arrays, unless you absolutely want to keep a chan of strings :
package main
import "fmt"
func main() {
ch := make(chan []string)
values := []string{"lol", "cat", "lolcat"}
go func() {
ch <- values
}()
fmt.Printf("Values : %+v
", <-ch)
}