iter

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2021 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package iter implements an iterator interface as used by query.

An iterator as implemented in this package is a type that may point to an element that can be looked at via Peek. Peek may only be called if the iterator is not empty, i.e. after the last element it iterates over. This can be checked via IsEmpty. Move the iterator to its next element (or the end) via calls to Next.

Next and Peek are allowed to panic if IsEmpty returns true.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConstIter

type ConstIter interface {
	Peek() interface{}
	IsEmpty() bool
}

ConstIter contains all methods for an iterator that is not moved to the next element. As such, it is not very useful except as a parameter to a function that is not supposed to change the iterator.

type Iter

type Iter interface {
	ConstIter
	Next()
}

Iter is an iterator that can be moved to the next element. Otherwise it is the same as a ConstIter.

type SliceIter

type SliceIter struct {
	// contains filtered or unexported fields
}

SliceIter is a helper type that takes any slice type and returns an iterator pointing to the first element of the slice.

func NewSliceIter

func NewSliceIter(slice interface{}) *SliceIter

NewSliceIter takes any slice type parameter and returns a *SliceIter that is guaranteed to implement Iter.

Calling NewSliceIter with other values is not allowed and might cause a panic.

func (SliceIter) IsEmpty

func (s SliceIter) IsEmpty() bool

IsEmpty returns whether the iterator points to a valid slice element.

func (*SliceIter) Next

func (s *SliceIter) Next()

Next moves the iterator to the next element of the slice. If the iterator points to the last slice element, the iterator is empty after this call.

func (SliceIter) Peek

func (s SliceIter) Peek() interface{}

Peek returns the current slice element.

Jump to

Keyboard shortcuts

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