iterators

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package iterators define storage iterator interfaces and some utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEach

func ForEach[T any](i Iterator[T], cb func(T) error) error

ForEach calls given callback for each iterator element.

NOTE: ForEach does not close iterator.

Types

type EmptyIterator

type EmptyIterator[T any] struct{}

EmptyIterator returns zero elements.

func Empty

func Empty[T any]() *EmptyIterator[T]

Empty creates new empty iterator

func (*EmptyIterator[T]) Close

func (i *EmptyIterator[T]) Close() error

Close closes iterator.

func (*EmptyIterator[T]) Err

func (i *EmptyIterator[T]) Err() error

Err returns an error caused during iteration, if any.

func (*EmptyIterator[T]) Next

func (i *EmptyIterator[T]) Next(*T) bool

Next returns true, if there is element and fills t.

type Iterator

type Iterator[T any] interface {
	// Next returns true, if there is element and fills t.
	Next(t *T) bool
	// Err returns an error caused during iteration, if any.
	Err() error
	// Close closes iterator.
	Close() error
}

Iterator is an storage iterator interface.

type SliceIterator

type SliceIterator[T any] struct {
	// contains filtered or unexported fields
}

SliceIterator is a slice iterator.

func Slice

func Slice[T any](vals []T) *SliceIterator[T]

Slice creates new SliceIterator from given values.

func (*SliceIterator[T]) Close

func (i *SliceIterator[T]) Close() error

Close closes iterator.

func (*SliceIterator[T]) Err

func (i *SliceIterator[T]) Err() error

Err returns an error caused during iteration, if any.

func (*SliceIterator[T]) Next

func (i *SliceIterator[T]) Next(t *T) bool

Next returns true, if there is element and fills t.

Jump to

Keyboard shortcuts

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