mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-11 09:33:50 +00:00
17 lines
280 B
Go
17 lines
280 B
Go
|
package fixedpoint
|
||
|
|
||
|
type Reducer func(prev, curr Value) Value
|
||
|
|
||
|
func Reduce(values []Value, init Value, reducer Reducer) Value {
|
||
|
if len(values) == 0 {
|
||
|
return init
|
||
|
}
|
||
|
|
||
|
r := reducer(init, values[0])
|
||
|
for i := 1; i < len(values); i++ {
|
||
|
r = reducer(r, values[i])
|
||
|
}
|
||
|
|
||
|
return r
|
||
|
}
|