Added index slice
All checks were successful
ci / deploy (push) Successful in 50s

This commit is contained in:
Leon Mika 2025-02-02 09:18:51 +11:00
parent 5dcbffe270
commit 97d4b9b4a1

View file

@ -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
}