add group by to docs

This commit is contained in:
Ruidy 2023-06-07 14:49:55 +02:00
parent 4042208482
commit 054679fb18
3 changed files with 23 additions and 2 deletions

View file

@ -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

View file

@ -9,10 +9,9 @@ title: _Underscore
![underscore](https://socialify.git.ci/rjNemo/underscore/image?description=1&font=KoHo&language=1&logo=https%3A%2F%2Fraw.githubusercontent.com%2FrjNemo%2Funderscore%2Fmain%2Fdocs%2Fstatic%2Flogo.png&owner=1&pattern=Floating%20Cogs&stargazers=1&theme=Dark) ![underscore](https://socialify.git.ci/rjNemo/underscore/image?description=1&font=KoHo&language=1&logo=https%3A%2F%2Fraw.githubusercontent.com%2FrjNemo%2Funderscore%2Fmain%2Fdocs%2Fstatic%2Flogo.png&owner=1&pattern=Floating%20Cogs&stargazers=1&theme=Dark)
`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

View 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}}
}
```