-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_map_test.go
More file actions
42 lines (34 loc) · 953 Bytes
/
example_map_test.go
File metadata and controls
42 lines (34 loc) · 953 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package concurrent_test
import (
"fmt"
"strconv"
concurrent "github.com/RPG-18/concurrent"
)
func ExampleMapped() {
numbers := []int{1, 2, 3, 4, 5, 6}
strings, _ := concurrent.Mapped(4, numbers, func(value int) string {
return strconv.Itoa(value)
})
fmt.Println(strings)
}
func ExampleMap() {
numbers := []int{1, 2, 3, 4, 5, 6}
_ = concurrent.Map(4, numbers, func(value *int) {
*value *= 2
})
fmt.Println(numbers)
}
func ExampleMappedReduced() {
numbers := []int{1, 2, 3, 4, 5, 6}
ordered, _ := concurrent.MappedReduced(3, numbers, func(value int) string {
return strconv.Itoa(value)
}, func(sum *string, value string) {
*sum = *sum + value
}, concurrent.OrderedReduce)
unordered, _ := concurrent.MappedReduced(3, numbers, func(value int) string {
return strconv.Itoa(value)
}, func(sum *string, value string) {
*sum = *sum + value
}, concurrent.UnorderedReduce)
fmt.Println(ordered, unordered) // 123456 142536
}