diff --git a/op_array/util.go b/op_array/util.go index 5c7cf04..9d229a0 100644 --- a/op_array/util.go +++ b/op_array/util.go @@ -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 +}