-
Notifications
You must be signed in to change notification settings - Fork 0
/
reduce.go
173 lines (158 loc) · 3.5 KB
/
reduce.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package functional
// DO NOT EDIT.
// Code generated by cmd/generate.go
// source: reduce.tmpl
// ReduceUint ...
func ReduceUint(slice []uint, fn func(x uint, y uint) uint) (ret uint) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceUint8 ...
func ReduceUint8(slice []uint8, fn func(x uint8, y uint8) uint8) (ret uint8) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceUint16 ...
func ReduceUint16(slice []uint16, fn func(x uint16, y uint16) uint16) (ret uint16) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceUint32 ...
func ReduceUint32(slice []uint32, fn func(x uint32, y uint32) uint32) (ret uint32) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceUint64 ...
func ReduceUint64(slice []uint64, fn func(x uint64, y uint64) uint64) (ret uint64) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceInt ...
func ReduceInt(slice []int, fn func(x int, y int) int) (ret int) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceInt8 ...
func ReduceInt8(slice []int8, fn func(x int8, y int8) int8) (ret int8) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceInt16 ...
func ReduceInt16(slice []int16, fn func(x int16, y int16) int16) (ret int16) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceInt32 ...
func ReduceInt32(slice []int32, fn func(x int32, y int32) int32) (ret int32) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceInt64 ...
func ReduceInt64(slice []int64, fn func(x int64, y int64) int64) (ret int64) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceFloat32 ...
func ReduceFloat32(slice []float32, fn func(x float32, y float32) float32) (ret float32) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceFloat64 ...
func ReduceFloat64(slice []float64, fn func(x float64, y float64) float64) (ret float64) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceBool ...
func ReduceBool(slice []bool, fn func(x bool, y bool) bool) (ret bool) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}
// ReduceString ...
func ReduceString(slice []string, fn func(x string, y string) string) (ret string) {
if len(slice) < 2 {
panic("reduce: slice too short")
}
ret = slice[0]
for i := 1; i < len(slice); i++ {
ret = fn(ret, slice[i])
}
return
}