Sobes.tech
Junior

Merge channels into one

livecode

Task condition

Implement a function merge that takes an arbitrary number of channels chan string and returns a single output channel from which all values from the passed channels can be read. The passed channels are closed after writing. The function should terminate correctly and close the output channel when all input channels are closed. After finishing reading from the merged channel, the program should output "ok".

func main() {
    for item := range merge(...) {
        // ...
    }
    fmt.Println("ok")
}

func merge(chs ...chan string) chan string {
    // write here
}