新增一系列数组操作的工具函数 #12

Merged
zhangdeman merged 8 commits from feature/arr_util into master 2025-12-04 10:49:44 +08:00
54262a7525 feat: 增加数组转Map方法
白茶清欢
2025-11-25 11:33:30 +08:00
Commit 1 of 8
Show all commits
+18
View File
@@ -0,0 +1,18 @@
// Package op_array ...
//
// Description : op_array ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-11-25 11:30
package op_array
// ToMap 数组转map
func ToMap[Key comparable, Value any](dataList []Value, keyFormat func(item Value) Key) map[Key]Value {
res := make(map[Key]Value)
for _, item := range dataList {
key := keyFormat(item)
res[key] = item
}
return res
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.