Skip to content

Commit

Permalink
feat: add to slice
Browse files Browse the repository at this point in the history
  • Loading branch information
hyphen committed Feb 26, 2024
1 parent cb029ab commit c90f789
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions gmap/gmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,19 @@ func ToSlice[K comparable, V, T any](m map[K]V, fc func(K, V) T) []T {
}
return ret
}

func CollectKey[K comparable, V any](m map[K]V) []K {
ret := make([]K, 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))
for _, v := range m {
ret = append(ret, v)
}
return ret
}

0 comments on commit c90f789

Please sign in to comment.