Skip to content

Commit

Permalink
fix: invalid slice init
Browse files Browse the repository at this point in the history
  • Loading branch information
hyphen committed Feb 26, 2024
1 parent c90f789 commit c07d0d8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions gmap/gmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ func SafeStore[K comparable, V any, M ~map[K]V](m M, k K, v V) {
}

func ToSlice[K comparable, V, T any](m map[K]V, fc func(K, V) T) []T {
ret := make([]T, len(m))
ret := make([]T, 0, len(m))
for k, v := range m {
ret = append(ret, fc(k, v))
}
return ret
}

func CollectKey[K comparable, V any](m map[K]V) []K {
ret := make([]K, len(m))
ret := make([]K, 0, len(m))
for k := range m {
ret = append(ret, k)
}
return ret
}

func CollectValue[K comparable, V any](m map[K]V) []V {
ret := make([]V, len(m))
ret := make([]V, 0, len(m))
for _, v := range m {
ret = append(ret, v)
}
Expand Down

0 comments on commit c07d0d8

Please sign in to comment.