From d3eb702c7449a52ee7097e326e4d2f5a76d264c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 25 Nov 2025 11:36:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=8F=90=E5=8F=96?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E6=8C=87=E5=AE=9A=E5=AD=97=E6=AE=B5,=20?= =?UTF-8?q?=E5=B9=B6=E7=94=9F=E6=88=90=E6=96=B0=E7=9A=84=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- op_array/util.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 +}