types/views: remove various Map Range funcs; use iterators everywhere

The remaining range funcs in the tree are RangeOverTCPs and
RangeOverWebs in ServeConfig; those will be cleaned up separately.

Updates #12912

Change-Id: Ieeae4864ab088877263c36b805f77aa8e6be938d
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2025-01-04 11:50:48 -08:00
committed by Brad Fitzpatrick
parent 47bd0723a0
commit 4b56bf9039
2 changed files with 45 additions and 86 deletions

View File

@@ -415,16 +415,6 @@ func (m *MapSlice[K, V]) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, &m.ж)
}
// Range calls f for every k,v pair in the underlying map.
// It stops iteration immediately if f returns false.
func (m MapSlice[K, V]) Range(f MapRangeFn[K, Slice[V]]) {
for k, v := range m.ж {
if !f(k, SliceOf(v)) {
return
}
}
}
// AsMap returns a shallow-clone of the underlying map.
//
// If V is a pointer type, it is the caller's responsibility to make sure the
@@ -527,16 +517,6 @@ func (m Map[K, V]) AsMap() map[K]V {
// Implementations should return false to stop range.
type MapRangeFn[K comparable, V any] func(k K, v V) (cont bool)
// Range calls f for every k,v pair in the underlying map.
// It stops iteration immediately if f returns false.
func (m Map[K, V]) Range(f MapRangeFn[K, V]) {
for k, v := range m.ж {
if !f(k, v) {
return
}
}
}
// All returns an iterator iterating over the keys
// and values of m.
func (m Map[K, V]) All() iter.Seq2[K, V] {
@@ -600,16 +580,6 @@ func (m MapFn[K, T, V]) GetOk(k K) (V, bool) {
return m.wrapv(v), ok
}
// Range calls f for every k,v pair in the underlying map.
// It stops iteration immediately if f returns false.
func (m MapFn[K, T, V]) Range(f MapRangeFn[K, V]) {
for k, v := range m.ж {
if !f(k, m.wrapv(v)) {
return
}
}
}
// All returns an iterator iterating over the keys and value views of m.
func (m MapFn[K, T, V]) All() iter.Seq2[K, V] {
return func(yield func(K, V) bool) {