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 16b0d11 commit cb029ab
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gmap/gmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ func SafeStore[K comparable, V any, M ~map[K]V](m M, k K, v V) {
}
m[k] = v
}

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

0 comments on commit cb029ab

Please sign in to comment.