underscore/docs/content/collections/each.md
Ruidy d19fa7b8c9
docsite (#19)
* change documentation theme and structure

* add config files

* fix links

* add build doc command

Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-23 10:32:56 -04:00

25 lines
449 B
Markdown

---
title: "Each"
date: 2022-03-21T13:30:59-04:00
---
`Each` iterates over a slice of elements, yielding each in turn to an action function.
```go
package main
import (
"fmt"
u "github.com/rjNemo/underscore"
)
func main() {
names := []string{"Alice", "Bob", "Charles"}
res := make([]string, 0)
u.Each(names, func(n string) {
res = append(res, fmt.Sprintf("Hi %s", n))
})
fmt.Println(res) // {"Hi Alice", "Hi Bob", "Hi Charles"}
}
```