Passed
Pull Request — master (#66)
by Hayrullah
56s
created

gotil.Reduce   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
nop 3
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