Files
lo/docs/data/it-foreach.md
T
Nathan Baulch e7386d9246 lint: fix inconsistent callback function parameter names (#730)
* Fix linting

* Use is.ElementsMatch

This will ignore the ordering of the final intersection. Especially
important when checking old versions of go that do not guarantee an order
when iterating through maps.

* lint: fix inconsistent callback function parameter names

* lint: rename "iteratee" to "transform" for *Map helpers

* lint: rename "project" parameters to "transform"

* lint: rename "cb" parameters to "callback"

* lint: rename "iteratee" to "callback" for ForEach helpers

---------

Co-authored-by: Franky W. <frankywahl@users.noreply.github.com>
Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
2025-11-06 18:05:11 +01:00

877 B

name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures playUrl variantHelpers similarHelpers position
ForEach foreach it/seq.go#L166 it sequence
func ForEach[T any](collection iter.Seq[T], callback func(item T))
https://go.dev/play/p/agIsKpG-S-P
it#sequence#foreach
it#sequence#foreachi
core#slice#foreach
it#sequence#map
40

Iterates over elements and invokes a callback function for each element.

Examples:

seq := func(yield func(int) bool) {
    _ = yield(1)
    _ = yield(2)
    _ = yield(3)
}
var result []int
it.ForEach(seq, func(item int) {
    result = append(result, item*2)
})
// result contains 2, 4, 6
seq := func(yield func(string) bool) {
    _ = yield("hello")
    _ = yield("world")
}
it.ForEach(seq, func(item string) {
    fmt.Println("Item:", item)
})
// Prints: Item: hello
//        Item: world