From 09c64ba2541c9fefb6bc1564bce7904df899a04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 25 Dec 2025 17:47:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E5=88=86=E8=AF=B8=E4=BE=AF=E8=81=9A=E5=90=88=E5=88=B0=E5=AF=B9?= =?UTF-8?q?=E5=BA=94key=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- op_array/util.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/op_array/util.go b/op_array/util.go index 2c3627b..0137d0f 100644 --- a/op_array/util.go +++ b/op_array/util.go @@ -72,6 +72,16 @@ func Group[Key comparable, Value any](dataList []Value, keyFormat func(item Valu return res } +// GroupToMap 数组数据按照指定 key 进行分组 +func GroupToMap[Key comparable, Value any](dataList []Value, keyFormat func(item Value) Key) map[Key][]Value { + dataTable := make(map[Key][]Value) + for _, item := range dataList { + key := keyFormat(item) + dataTable[key] = append(dataTable[key], item) + } + return dataTable +} + // TreeItem 数据结构 type TreeItem[ID comparable, Value any] struct { ID ID `json:"id" dc:"数据ID"`