diff --git a/Makefile b/Makefile index 074cbde..5baa33d 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ scan: scan-config: trivy config . +.PHONY: docs docs: cd docs && hugo server -D diff --git a/docs/content/_index.md b/docs/content/_index.md index f717fe2..cbaaacb 100644 --- a/docs/content/_index.md +++ b/docs/content/_index.md @@ -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` 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 diff --git a/docs/content/collections/groupby.md b/docs/content/collections/groupby.md new file mode 100644 index 0000000..04cb548 --- /dev/null +++ b/docs/content/collections/groupby.md @@ -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}} +} +```