Skip to content

Commit bb449a6

Browse files
committed
entries slice to map
1 parent 9a66fc6 commit bb449a6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

slice.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ func ToMap[T comparable](in []T) (out map[T]struct{}) {
4949
return
5050
}
5151

52+
func Entries[T any, K comparable, V any](in []T, call func(T) (K, V)) (out map[K]V) {
53+
out = make(map[K]V, len(in))
54+
for _, val := range in {
55+
k, v := call(val)
56+
out[k] = v
57+
}
58+
return
59+
}
60+
5261
func Reduce[T any](in []T, call func(result, value T, index int) T) (out T) {
5362
for i, v := range in {
5463
out = call(out, v, i)

0 commit comments

Comments
 (0)