From 54262a7525099adc26fb68adade5a9274958a476 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:33:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E8=BD=ACMap=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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 op_array/util.go diff --git a/op_array/util.go b/op_array/util.go new file mode 100644 index 0000000..5c7cf04 --- /dev/null +++ b/op_array/util.go @@ -0,0 +1,18 @@ +// Package op_array ... +// +// Description : op_array ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2025-11-25 11:30 +package op_array + +// ToMap 数组转map +func ToMap[Key comparable, Value any](dataList []Value, keyFormat func(item Value) Key) map[Key]Value { + res := make(map[Key]Value) + for _, item := range dataList { + key := keyFormat(item) + res[key] = item + } + return res +}