feat: 增加数组分诸侯聚合到对应key的逻辑
This commit is contained in:
@ -72,6 +72,16 @@ func Group[Key comparable, Value any](dataList []Value, keyFormat func(item Valu
|
|||||||
return res
|
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 数据结构
|
// TreeItem 数据结构
|
||||||
type TreeItem[ID comparable, Value any] struct {
|
type TreeItem[ID comparable, Value any] struct {
|
||||||
ID ID `json:"id" dc:"数据ID"`
|
ID ID `json:"id" dc:"数据ID"`
|
||||||
|
|||||||
Reference in New Issue
Block a user