feat: 增加提取数组指定字段, 并生成新的数组

This commit is contained in:
zhangdeman committed 2025-11-25 11:36:20 +08:00
1 parent 54262a7525
commit d3eb702c74
1 file changed
+10
+10
View File
@@ -16,3 +16,13 @@ func ToMap[Key comparable, Value any](dataList []Value, keyFormat func(item Valu
}
return res
}
// ExtractField 提取数组指定字段, 并构建成一个新的数组
func ExtractField[FieldValue any, Value any](dataList []Value, fieldValue func(item Value) FieldValue) []FieldValue {
res := make([]FieldValue, 0)
for _, item := range dataList {
v := fieldValue(item)
res = append(res, v)
}
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.