aboutsummaryrefslogtreecommitdiff
path: root/example_map_test.go
blob: 5ec879fc01dd9718b3ac61a9489dc0e95f4cd22e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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]
}