Skip to content

Commit

Permalink
add iters for container/history
Browse files Browse the repository at this point in the history
  • Loading branch information
mkideal committed Aug 15, 2024
1 parent 4bd134a commit 6ca6108
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
23 changes: 23 additions & 0 deletions container/history/map_iter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//go:build go1.23

package history

import (
"iter"
"maps"
)

// All returns an iterator over key-value pairs in the map
func (m Map[K, V]) All() iter.Seq2[K, V] {
return maps.All(m.data)
}

// Keys returns an iterator over the map keys
func (m Map[K, V]) Keys() iter.Seq[K] {
return maps.Keys(m.data)
}

// Values returns an iterator over the map values
func (m Map[K, V]) Values() iter.Seq[V] {
return maps.Values(m.data)
}
13 changes: 13 additions & 0 deletions container/history/set_iter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build go1.23

package history

import (
"iter"
"maps"
)

// All returns an iterator over keys in the set
func (s Set[K]) All() iter.Seq[K] {
return maps.Keys(s.data)
}
23 changes: 23 additions & 0 deletions container/history/slice_iter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//go:build go1.23

package history

import (
"iter"
"slices"
)

// All returns an iterator over index-value pairs in the slice
func (s Slice[T]) All() iter.Seq2[int, T] {
return slices.All(s.data)
}

// Backward returns an iterator over index-value pairs in the slice,
func (s Slice[T]) Backward() iter.Seq2[int, T] {
return slices.Backward(s.data)
}

// Values returns an iterator that yields the slice elements in order.
func (s Slice[T]) Values() iter.Seq[T] {
return slices.Values(s.data)
}

0 comments on commit 6ca6108

Please sign in to comment.