Total Lines | 13 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package gotil |
||
2 | |||
3 | import "github.com/gotilty/gotil/internal" |
||
4 | |||
5 | // Reduce iterates given collection and returns the accumulated result of running each element |
||
6 | // the last param is initial value of accumulator. |
||
7 | // data := []int{5, 10} |
||
8 | // result, _ := Reduce(data, func(accumulator, val interface{}, i int) interface{} { |
||
9 | // return accumulator.(int) + val.(int) |
||
10 | // }, 0) |
||
11 | // // Output: 15 |
||
12 | func Reduce(a interface{}, f func(accumulator interface{}, val interface{}, i int) interface{}, accumulator interface{}) (interface{}, error) { |
||
13 | return internal.Reduce(a, f, accumulator) |
||
14 | } |
||
15 |