diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-04-07 21:36:40 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-04-07 21:36:40 +0300 |
commit | 9cd6b0fca87679e570fbdd4942e3068feb3439fa (patch) | |
tree | 557bf877d71854480f4171e9dd324cebb5606056 /example_map_test.go |
initial
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] +} |