Skip to content

Instantly share code, notes, and snippets.

@ripperdev
Created December 27, 2022 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ripperdev/c91babc583caa2f618b67ee7f483b521 to your computer and use it in GitHub Desktop.
Save ripperdev/c91babc583caa2f618b67ee7f483b521 to your computer and use it in GitHub Desktop.
func GroupBy(data any) map[string][]ObjForGroupBy {
datas := reflect.ValueOf(data)
var result = make(map[string][]ObjForGroupBy)
l := datas.Len()
for i := 0; i < l; i++ {
obj := datas.Index(i).Interface().(ObjForGroupBy)
strV := obj.GetValueForGroupBy()
result[strV] = append(result[strV], obj)
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment