From 78e1c33e3019014c9b72e8c58a998f11bd44f6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 16 Jun 2024 17:14:21 +0200 Subject: [PATCH] v0.0.475 ArrGroupBy --- go.mod | 2 +- go.sum | 2 ++ goextVersion.go | 4 ++-- langext/array.go | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b993292..06e3014 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/jmoiron/sqlx v1.4.0 github.com/rs/xid v1.5.0 github.com/rs/zerolog v1.33.0 - go.mongodb.org/mongo-driver v1.15.0 + go.mongodb.org/mongo-driver v1.15.1 golang.org/x/crypto v0.24.0 golang.org/x/sys v0.21.0 golang.org/x/term v0.21.0 diff --git a/go.sum b/go.sum index ca4ac9c..0c5b3a5 100644 --- a/go.sum +++ b/go.sum @@ -218,6 +218,8 @@ go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= go.mongodb.org/mongo-driver v1.15.0 h1:rJCKC8eEliewXjZGf0ddURtl7tTVy1TK3bfl0gkUSLc= go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= +go.mongodb.org/mongo-driver v1.15.1 h1:l+RvoUOoMXFmADTLfYDm7On9dRm7p4T80/lEQM+r7HU= +go.mongodb.org/mongo-driver v1.15.1/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= diff --git a/goextVersion.go b/goextVersion.go index a8a4830..bb1923e 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.474" +const GoextVersion = "0.0.475" -const GoextVersionTimestamp = "2024-06-14T23:18:58+0200" +const GoextVersionTimestamp = "2024-06-16T17:14:21+0200" diff --git a/langext/array.go b/langext/array.go index 63c6bc0..9ab975b 100644 --- a/langext/array.go +++ b/langext/array.go @@ -564,3 +564,18 @@ func ArrChunk[T any](arr []T, chunkSize int) [][]T { return res } + +func ArrGroupBy[T1 any, T2 comparable](arr []T1, groupfunc func(v T1) T2) map[T2][]T1 { + r := make(map[T2][]T1) + + for _, v := range arr { + key := groupfunc(v) + if _, ok := r[key]; ok { + r[key] = append(r[key], v) + } else { + r[key] = []T1{v} + } + } + + return r +}