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

reduce.go   A

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
dl 0
loc 13
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A gotil.Reduce 0 2 1
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