Preferred title in entries & unused fields in contents

This commit is contained in:
Simon Martens
2025-02-09 14:05:27 +01:00
parent 851de285aa
commit 1b54e0aef1
5 changed files with 62 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
package datatypes
// INFO: use this if your key is unique
func MakeMap[T any, U comparable](data []T, f func(T) U) map[U]T {
m := make(map[U]T)
for _, v := range data {
@@ -7,3 +8,12 @@ func MakeMap[T any, U comparable](data []T, f func(T) U) map[U]T {
}
return m
}
// INFO: use this if your key is not unique
func MakeMultiMap[T any, U comparable](data []T, f func(T) U) map[U][]T {
m := make(map[U][]T)
for _, v := range data {
m[f(v)] = append(m[f(v)], v)
}
return m
}