collection/example_map_test.go

27 lines
525 B
Go
Raw Permalink Normal View History

2022-04-07 21:36:40 +03:00
package collection
import (
"fmt"
"strings"
)
func ExampleMap() {
collection := []int{1, 2, 3, 4, 5}
cb := func(v int, idx int) string {
return fmt.Sprintf("[%d]", v)
}
result := Map(collection, cb)
fmt.Println(strings.Join(result, "_"))
// Output: [1]_[2]_[3]_[4]_[5]
}
func ExampleMapSync() {
collection := []int{1, 2, 3, 4, 5}
cb := func(v int, idx int) string {
return fmt.Sprintf("[%d]", v)
}
result := MapSync(collection, cb)
fmt.Println(strings.Join(result, "_"))
// Output: [1]_[2]_[3]_[4]_[5]
}