Help us shape the future of Go! Take the 2026 Go Developer Survey

iterator

package
v1.28.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToSlice

func ToSlice[T any](it Iterator[T]) []T

ToSlice returns a slice that contains all of the elements from [it] in order. [it] will be released before returning.

Types

type Empty

type Empty[T any] struct{}

Empty is an iterator with no elements.

func (Empty[_]) Next

func (Empty[_]) Next() bool

func (Empty[_]) Release

func (Empty[_]) Release()

func (Empty[T]) Value

func (Empty[T]) Value() T

type Iterator

type Iterator[T any] interface {
	// Next attempts to move the iterator to the next element in the set. It
	// returns false once there are no more elements to return.
	Next() bool

	// Value returns the value of the current element. Value should only be called
	// after a call to Next which returned true.
	Value() T

	// Release any resources associated with the iterator. This must be called
	// after the iterator is no longer needed.
	Release()
}

Iterator defines an interface for iterating over a set.

func Deduplicate

func Deduplicate[T comparable](it Iterator[T]) Iterator[T]

Deduplicate returns an iterator that skips the elements that have already been returned from [it].

func Filter

func Filter[T any](it Iterator[T], filter func(T) bool) Iterator[T]

Filter returns an iterator that skips the elements in [it] that return true from [filter].

func FromSlice

func FromSlice[T any](elements ...T) Iterator[T]

FromSlice returns an iterator that contains [elements] in order. Doesn't sort by anything.

func FromTree

func FromTree[T any](btree *btree.BTreeG[T]) Iterator[T]

FromTree returns a new iterator of the stakers in [tree] in ascending order. Note that it isn't safe to modify [tree] while iterating over it.

func Merge

func Merge[T any](less btree.LessFunc[T], iterators ...Iterator[T]) Iterator[T]

Merge returns an iterator that returns all of the elements of [iterators] in order.

Directories

Path Synopsis
Package iteratormock is a generated GoMock package.
Package iteratormock is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL