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

group_by.go   A

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A gotil.GroupBy 0 2 1
1
package gotil
2
3
import (
4
	"github.com/gotilty/gotil/internal"
5
)
6
7
// GroupBy iterates over elements of collection, returns an object of fist element predicate if returns true for.
8
// 		data := []float64{5, 10.5, 10, 20, 10.75, 100, 4.23, 5.15, 5.99, 100.0001}
9
// 		if result, err := GroupBy(data, func(a interface{}, i interface{}) interface{} {
10
// 			return math.Floor(a.(float64))
11
// 		}); err == nil {
12
// 			fmt.Println(result)
13
// 		}
14
// 		// Output: map[4:[4.23] 5:[5 5.15 5.99] 10:[10.5 10 10.75] 20:[20] 100:[100 100.0001]]
15
func GroupBy(a interface{}, f func(val, i interface{}) interface{}) (interface{}, error) {
16
	return internal.GroupBy(a, f)
17
}
18