This commit is contained in:
parent
5dcbffe270
commit
97d4b9b4a1
|
@ -28,3 +28,11 @@ func FromSliceWithError[T any, K comparable, V any](ts []T, fn func(t T) (K, V,
|
|||
}
|
||||
return kvs, nil
|
||||
}
|
||||
|
||||
func IndexSlice[T any, K comparable](ts []T, fn func(t T) K) map[K]T {
|
||||
m, _ := FromSliceWithError(ts, func(t T) (k K, _ T, _ error) {
|
||||
k = fn(t)
|
||||
return k, t, nil
|
||||
})
|
||||
return m
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue