Skip to content

Commit

Permalink
feat: add Values method to SyncMap for retrieving all values
Browse files Browse the repository at this point in the history
  • Loading branch information
simulot committed Mar 9, 2025
1 parent fffdf8b commit 3b50d9a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/gen/syncmap/syncmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package syncmap

// SyncMap is a thread-safe and type-safe map based on sync.Map.

import "sync"
import (
"sync"
)

type SyncMap[K comparable, V any] struct {
m sync.Map
Expand Down Expand Up @@ -118,3 +120,12 @@ func (m *SyncMap[K, V]) Keys() []K {
})
return all
}

func (m *SyncMap[K, V]) Values() []V {
all := make([]V, 0)
m.Range(func(key K, value V) bool {
all = append(all, value)
return true
})
return all
}

0 comments on commit 3b50d9a

Please # to comment.