mirror of
https://github.com/sablierapp/sablier.git
synced 2025-12-26 07:13:36 +01:00
14 lines
324 B
Go
14 lines
324 B
Go
package array
|
|
|
|
// GroupByProperty groups a slice of structs by a specific property.
|
|
func GroupByProperty[T any, K comparable](items []T, getProperty func(T) K) map[K][]T {
|
|
grouped := make(map[K][]T)
|
|
|
|
for _, item := range items {
|
|
key := getProperty(item)
|
|
grouped[key] = append(grouped[key], item)
|
|
}
|
|
|
|
return grouped
|
|
}
|