Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions iter/gomap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func (*goMapIter[K, V]) Err() error {

// FromMap produces an iterator of key-value pairs from a Go map.
// The resulting iterator never returns an error.
// Note that this is implemented in terms of [FromMapKeys],
// which makes copies the keys of the map to a new slice.
func FromMap[M ~map[K]V, K comparable, V any](m M) Of[Pair[K, V]] {
return &goMapIter[K, V]{
m: m,
Expand All @@ -33,6 +35,8 @@ func FromMap[M ~map[K]V, K comparable, V any](m M) Of[Pair[K, V]] {
}

// FromMapKeys produces an iterator over the keys of a Go map.
// Note that this is implemented in terms of [FromSlice],
// after first copying the keys of the map to a new slice.
func FromMapKeys[M ~map[K]V, K comparable, V any](m M) Of[K] {
keys := make([]K, 0, len(m))
for k := range m {
Expand Down
1 change: 1 addition & 0 deletions set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (s Of[T]) Eachx(f func(T) error) error {
// Iter produces an iterator over the members of the set,
// in an indeterminate order.
// The set may be nil.
// Note that this makes a copy of the elements in the set.
func (s Of[T]) Iter() iter.Of[T] {
return iter.FromMapKeys(s)
}
Expand Down