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

gotil.GroupBy   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 2
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