mirror of
https://github.com/ProtonMail/go-proton-api.git
synced 2026-04-25 01:14:58 -04:00
29 lines
592 B
Go
29 lines
592 B
Go
package utils
|
|
|
|
import (
|
|
"maps"
|
|
"slices"
|
|
)
|
|
|
|
// Keys returns a slice of keys from the map.
|
|
// Alternative to using maps.Keys which returns an iterator instead of a slice.
|
|
func Keys[M ~map[K]V, K comparable, V any](m M) []K {
|
|
keys := make([]K, 0, len(m))
|
|
|
|
return slices.AppendSeq(
|
|
keys,
|
|
maps.Keys(m),
|
|
)
|
|
}
|
|
|
|
// Values returns a slice of values from the map.
|
|
// Alternative to using maps.Values which returns an iterator instead of a slice.
|
|
func Values[M ~map[K]V, K comparable, V any](m M) []V {
|
|
values := make([]V, 0, len(m))
|
|
|
|
return slices.AppendSeq(
|
|
values,
|
|
maps.Values(m),
|
|
)
|
|
}
|