added Store.Keys()

This commit is contained in:
Gani Georgiev committed 2026-08-21 14:45:48 +03:00
1 parent bf1f164014
commit 25dc8a8eea
2 files changed
+36 -1

No files matched your search

+15 -1
View File
@@ -122,7 +122,21 @@ func (s *Store[K, T]) GetAll() map[K]T {
return clone
}
// Values returns a slice with all of the current store values.
// Keys returns a slice with all of the store keys.
func (s *Store[K, T]) Keys() []K {
s.mu.RLock()
defer s.mu.RUnlock()
var keys = make([]K, 0, len(s.data))
for k := range s.data {
keys = append(keys, k)
}
return keys
}
// Values returns a slice with all of the store values.
func (s *Store[K, T]) Values() []T {
s.mu.RLock()
defer s.mu.RUnlock()