ranger

package
v0.0.0-...-4998ed7 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package ranger provides the Ranger interface that iterates over a set of values, and some implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashEntry

type HashEntry struct {
	Key   string
	Value interface{}
}

type Ranger

type Ranger interface {
	// Next advances the ranger to the next value in the set. It returns whether it was successful in advancing.
	Next() bool

	// Value returns the current value in the set. Value panics if Next has not been called or if
	// there are no more values.
	Value() interface{}

	// Status returns the current iteration status. Status panics if Next has not been called or if
	// there are no more values.
	Status() Status
}

Ranger iterates over a set of values and returns the current value for each iteration.

func New

func New(v interface{}) Ranger

New returns a ranger that iterates over a slice, an array, or a hash. New panics if v is nil, or if it is of another type. If v is a hash, the ranger will produce HashEntry elements.

func NewFromTo

func NewFromTo(minInclusive int, maxInclusive int) Ranger

NewFromTo returns a Ranger that iterates over a range of integer values. NewFromTo panics if maxInclusive is less than minInclusive.

func NewInt

func NewInt(minInclusive int, maxExclusive int) Ranger

NewInt returns a Ranger that iterates over a range of integer values. NewInt panics if maxExclusive is not greater than or equal to minInclusive.

type Status

type Status struct {
	Index   int
	First   bool
	Last    bool
	Even    bool
	Odd     bool
	HasMore bool
}

Jump to

Keyboard shortcuts

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