iterator

package
v0.0.0-...-5bd4ecb Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package iterator implements a generic iterator protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cycle

type Cycle[T any] struct {
	Iterator[T]
}

func NewCycle

func NewCycle[T any](data []T) *Cycle[T]

NewCycle creates a new cycle iterator for the given slice of elements.

func (*Cycle[T]) Next

func (it *Cycle[T]) Next() bool

Next increments the iterator index. It always returns true as it resets the index to cycle around.

func (*Cycle[T]) Value

func (it *Cycle[T]) Value() T

Value returns the element at the current iterator index. Next must have been called prior to a call to Value.

type Iterator

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

func New

func New[T any](data []T) *Iterator[T]

New creates a new iterator for the given slice of elements.

func (*Iterator[T]) Index

func (it *Iterator[T]) Index() int

Index returns the index of the current element.

func (*Iterator[T]) Len

func (it *Iterator[T]) Len() int

Len returns the remaining number of items to be iterated over.

func (*Iterator[T]) Move

func (it *Iterator[T]) Move(i int)

Move moves the iterator i number of elements forward.

func (*Iterator[T]) Next

func (it *Iterator[T]) Next() bool

Next returns true if there are any elements remaining to iterate, false otherwise.

func (*Iterator[T]) Reset

func (it *Iterator[T]) Reset()

Reset resets the iterator index.

func (*Iterator[T]) Value

func (it *Iterator[T]) Value() T

Value returns the element at the current iterator index. Next must have been called prior to a call to Value. If the iterator is exhausted, which is saying the the current index is out of bounds for the data slice, it will return the zero value for the type T.

Jump to

Keyboard shortcuts

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