diff options
Diffstat (limited to 'example_map_test.go')
-rw-r--r-- | example_map_test.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/example_map_test.go b/example_map_test.go new file mode 100644 index 0000000..5ec879f --- /dev/null +++ b/example_map_test.go @@ -0,0 +1,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] +} |