MCPcopy Index your code
hub / github.com/riverqueue/river / KeyBy

Function KeyBy

rivershared/util/sliceutil/slice_util.go:36–45  ·  view source on GitHub ↗

KeyBy converts a slice into a map using the key/value tuples returned by tupleFunc. If any two pairs would have the same key, the last one wins. Go maps are unordered and the order of the new map isn't guaranteed to the same as the original slice.

(collection []T, tupleFunc func(item T) (K, V))

Source from the content-addressed store, hash-verified

34// maps are unordered and the order of the new map isn't guaranteed to the same
35// as the original slice.
36func KeyBy[T any, K comparable, V any](collection []T, tupleFunc func(item T) (K, V)) map[K]V {
37 result := make(map[K]V, len(collection))
38
39 for _, t := range collection {
40 k, v := tupleFunc(t)
41 result[k] = v
42 }
43
44 return result
45}
46
47// Map manipulates a slice and transforms it to a slice of another type.
48func Map[T any, R any](collection []T, mapFunc func(T) R) []R {

Callers 7

Test_Client_RetryPolicyFunction · 0.92
Test_Client_SubscribeFunction · 0.92
SubscribeConfigMethod · 0.92
StartMethod · 0.92
migrateDownMethod · 0.92
TestKeyByFunction · 0.85

Calls

no outgoing calls

Tested by 4

Test_Client_RetryPolicyFunction · 0.74
Test_Client_SubscribeFunction · 0.74
TestKeyByFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…