addrs: Set.All for iterating the set elements

Since an addrs.Set is really just a map with some special usage rules, this
is just a thin wrapper around maps.Values but (as with many of the other
methods on this type) avoids exposing that implementation detail in calling
code.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
This commit is contained in:
Martin Atkins 2026-02-03 16:01:20 -08:00
parent 08ba66ab6e
commit 6760b02f65

View file

@ -7,6 +7,7 @@ package addrs
import (
"iter"
"maps"
)
// Set represents a set of addresses of types that implement UniqueKeyer.
@ -42,6 +43,11 @@ func (s Set[T]) Has(addr T) bool {
return exists
}
// All returns a sequence of all addresses in the set in a pseudorandom order.
func (s Set[T]) All() iter.Seq[T] {
return maps.Values(s)
}
// Add inserts the given address into the set, if not already present. If
// an equivalent address is already in the set, this replaces that address
// with the new value.