Range calls f for every key/value pair in the map. Iteration stops early if f returns false. Range iterates over a snapshot of the map taken under a read lock; f is invoked without holding any lock, which means callbacks may safely call other methods on the same Map (including Store and Delete) wit
(f func(key K, value V) bool)
| 91 | // deadlocking. As a consequence, mutations performed during iteration are not |
| 92 | // reflected in the values seen by f. |
| 93 | func (m *Map[K, V]) Range(f func(key K, value V) bool) { |
| 94 | m.mu.RLock() |
| 95 | snapshot := maps.Clone(m.values) |
| 96 | m.mu.RUnlock() |
| 97 | |
| 98 | for k, v := range snapshot { |
| 99 | if !f(k, v) { |
| 100 | break |
| 101 | } |
| 102 | } |
| 103 | } |