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

Merged
zhangdeman merged 8 commits from feature/arr_util into master 2025-12-04 10:49:44 +08:00
38ff576682 feat: 增加转换自动以value值类型的转换方法
白茶清欢
2025-11-26 12:48:12 +08:00
Commit 4 of 8
Show all commits
+10
View File
@@ -17,6 +17,16 @@ func ToMap[Key comparable, Value any](dataList []Value, keyFormat func(item Valu
return res
}
// ToCustomMap 数组转map
func ToCustomMap[Key comparable, Value any, CustomValue any](dataList []Value, keyFormat func(item Value) Key, formatCustomValue func(item Value) CustomValue) map[Key]CustomValue {
res := make(map[Key]CustomValue)
for _, item := range dataList {
key := keyFormat(item)
res[key] = formatCustomValue(item)
}
return res
}
// ExtractField 提取数组指定字段, 并构建成一个新的数组
func ExtractField[FieldValue any, Value any](dataList []Value, fieldValue func(item Value) FieldValue) []FieldValue {
res := make([]FieldValue, 0)
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.