func fanIn[T any](inputs ...<-chan T) <-chan T { output := make(chan T) var wg sync.WaitGroup // Increment the wait group for each input channel wg.Add(len(inputs)) // Start a goroutine for each input channel for _, input := range inputs { go func(ch <-chan T) { defer wg.Done() for num := range ch { output <- num } }(input) } // Start a goroutine to wait for all inputs to be closed and then close the output channel go func() { wg.Wait() close(output) }() return output }