Skip to main content Link Search Menu Expand Document (external link)

ForEach

func (input *Channel[T]) ForEach(function func(T), opts ...options.ForEachOption) <-chan struct{}

ForEach calls the function passed as parameter for every value coming from the input channel.

The returned channel will close when all input values have been processed, or the pipeline is canceled.

Example

<-input.ForEach(func(x int) { fmt.Println(x)})

Console output:
1
2
3