From 38ff57668268c5e9a9192ea990fbbc4fce46cabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 26 Nov 2025 12:48:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E4=BB=A5value=E5=80=BC=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=9A=84=E8=BD=AC=E6=8D=A2=E6=96=B9=E6=B3=95?= 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 29854f6..9efa97e 100644 --- a/op_array/util.go +++ b/op_array/util.go @@ -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)