| Total Lines | 16 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |