feat: add universities and restaurants
This commit is contained in:
@ -31,3 +31,18 @@ func Map[T any, Tkey comparable, Tval any](s []T, transformFn func(i *T) (Tkey,
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func Group[T any, Tkey comparable, Tval any](s []T, groupFn func(i *T) (groupKey Tkey, value Tval)) (out map[Tkey][]Tval) {
|
||||
out = make(map[Tkey][]Tval)
|
||||
for _, i := range s {
|
||||
key, value := groupFn(&i)
|
||||
list, exists := out[key]
|
||||
if !exists {
|
||||
list = make([]Tval, 0, 2)
|
||||
}
|
||||
|
||||
out[key] = append(list, value)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user