cycler

package
v10.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotSlice is returned when NewCyclerFromSlice was not passed a input of type slice.
	ErrNotSlice = errors.New("values is not a slice")
	// ErrNoValues is returned when a cycler was initialized with no values.
	ErrNoValues = errors.New("no configured values")
)

Functions

This section is empty.

Types

type Cycler

type Cycler interface {
	// Get returns the current value in the cycler. It does not rotate the cycler.
	Get() interface{}
	// Next rotates the cycler and returns the next value.
	Next() interface{}
	// Seek rotates the cycler until it finds a specific value.
	// If the values is not found the cycler will remain in the same index.
	Seek(target interface{}) interface{}
	// Len returns the number of values in the cycler.
	Len() int
}

Cycler provides a way to cycle through a set of elements.

func NewCycler

func NewCycler(values ...interface{}) (Cycler, error)

NewCycler creates a Cycler from passed values. This will return an error if no elements are passed.

func NewCyclerFromSlice

func NewCyclerFromSlice(values interface{}) (Cycler, error)

NewCyclerFromSlice creates a Cycler from a slice. The cycler will contain all the elements in the slice. This will return an error if `values` is not a slice or if the slice does not contain any elements.

Jump to

Keyboard shortcuts

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