mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
add group by to docs
This commit is contained in:
parent
4042208482
commit
054679fb18
3 changed files with 23 additions and 2 deletions
1
Makefile
1
Makefile
|
|
@ -14,6 +14,7 @@ scan:
|
||||||
scan-config:
|
scan-config:
|
||||||
trivy config .
|
trivy config .
|
||||||
|
|
||||||
|
.PHONY: docs
|
||||||
docs:
|
docs:
|
||||||
cd docs && hugo server -D
|
cd docs && hugo server -D
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,9 @@ title: _Underscore
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
`underscore` is a `Go` library providing useful functional programming helpers without extending any built-in objects.
|
`underscore` is a `Go` library providing useful functional programming helpers without extending any built-in objects.
|
||||||
|
|
||||||
It is mostly a port from the `underscore.js` library based on generics brought by `go1.18`.
|
It is mostly a port from the `underscore.js` library based on generics available from `go1.18`.
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
|
|
|
||||||
21
docs/content/collections/groupby.md
Normal file
21
docs/content/collections/groupby.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
---
|
||||||
|
title: "Group by"
|
||||||
|
date: 2023-06-07T00:49:56+02:00
|
||||||
|
---
|
||||||
|
|
||||||
|
GroupBy splits a slice into a map[K][]V grouped by the result of the iterator function.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
u "github.com/rjNemo/underscore"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []float64{1.3, 2.1, 2.4}
|
||||||
|
groupingFunc := func(n float64) int { return int(math.Floor(n)) }
|
||||||
|
res := u.GroupBy(nums, groupingFunc) // { 1: {1.3}, 2: {2.1, 2.4}}
|
||||||
|
}
|
||||||
|
```
|
||||||
Loading…
Reference in a new issue