Skip to content

Commit

Permalink
优化集合的groupBy
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Apr 19, 2024
1 parent db74dac commit 84ad026
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions enumerable.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,13 @@ func (receiver Enumerable[T]) GroupBy(mapSlice any, getMapKeyFunc func(item T) a
}
// List集合
if mapValueIsListType {
// 在原来的List集合,做Add操作,必须保住该集合是指针类型
if findMapValue.Kind() != reflect.Pointer {
arrValues := types.GetListToArray(findMapValue)
arrValues := types.GetListToArrayValue(findMapValue)
findMapValue = types.ListNew(mapValueItemType)
for _, value := range arrValues {
types.ListAdd(findMapValue, value)
}
types.ListAddValue(findMapValue, arrValues)
}
types.ListAdd(findMapValue, item)
types.ListAddValue(findMapValue, reflect.ValueOf(item))
mapSliceVal.SetMapIndex(key, findMapValue.Elem())
} else {
mapValue := reflect.Append(findMapValue, reflect.ValueOf(item))
Expand Down

0 comments on commit 84ad026

Please sign in to comment.