i

package module
v0.0.0-...-1dc7587 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2016 License: MIT Imports: 0 Imported by: 0

README

i

No Maintenance Intended

This is my iterator library for Go. There are many like it, but this one is mine.

Documentation is available on GoDoc.

Documentation

Overview

Package i is an higher order library for Go that focuses on using iterators as an common interface for computation.

The i library defines the following interfaces for iterators:

type Iterator interface {
	Value() interface{}
	Error() error
	SetError(error)
}

The basic interface that is common to all iterators. Value() is used to access the value at the location that the iterator currently points to in the uderlying data stream.

Error() returns the last error occurred while using the iterator.

SetError() is used by iterators to assign an value to the last error.

Both Value() and Error() should always be idempotent.

type Forward interface {
	Iterator
	Next() error
	AtEnd() bool
}

The Forward iterator is an iterator that supports moving forward over the underlying data with the Next() method. The iterator should always be valid on the range [start, end). The AtEnd() method alows the user to check if the end of the data has been reached, that is at the end position. It should always be idempotent. Next() should return error if it is called beyond the end of the stream.

type BiDirectional interface {
	Forward
	Prev() error
	AtStart() bool
}

The BiDirectional iterator is a Forward iterator that provides a method to move backwards in the stream. AtStart() should inidcate when the iterator is at the start of the stream. Important difference from the AtEnd() method is that the iterator should be valid at the AtStart position but not at the AtEnd position.

type BoundedAtStart interface {
	Forward
	First() error
}

BoundedAtStart iterator is a Forward iterator that has an efficient method to reset the iterator to the starting position. The First() method should be idempotent.

type Bounded interface {
	BiDirectional
	First() error
	Last() error
}

The Bounded iterator is a BiDirectional iterator that has efficient ways to both reach the first position and the last position. Notice that while the the AtStart() method should return true after calling First(), the AtEnd() method should return false after calling Last() method, e.g. the last position should be a valid position. Calling Last() and then Next() should be valid and AtEnd() should return true after that.

type RandomAccess interface {
	Bounded
	Goto(int) error
	Len() int
}

The RandomAccess iterator is a Bounded iterator that both as a known length and an efficient way to jump into any valid position in the data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BiDirectional

type BiDirectional interface {
	// BiDirectional is a Forward iterator.
	Forward

	// Move to the previous position in the data. Moving once beyond the
	// starting position is valid. Moveing after that is an error.
	Prev() error

	// Check if the iterator is at the start of the data. This is a valid
	// position in the data, e.g. fetching the value will return the first
	// value.
	AtStart() bool
}

type Bounded

type Bounded interface {
	// Bounded is a BiDirectional iterator.
	BiDirectional

	// Jump to the first position in the stream. This is a valid position
	// in the stream. At this position AtStart() returns true.
	First() error

	// jump to the last position in the stream. This is a valid position
	// in the stream. At this position AtEnd() returns false.
	Last() error
}

type BoundedAtStart

type BoundedAtStart interface {
	// BoundedAtStart is a Forward iterator.
	Forward

	// Jump to the first position in the stream. This is a valid position
	// in the stream. At this position AtStart() returns true.
	First() error
}

type Forward

type Forward interface {
	// Forward iterator is an Iterator.
	Iterator

	// Move to the next position in the data. Moving after the end
	// is reached is an error.
	Next() error

	// Check if the iterator is beyond the end of the data. This is an
	// invalid position in the data, e.g. fetching the value at the
	// end is an error.
	AtEnd() bool
}

type Iterator

type Iterator interface {
	// Return value at current position in data.
	Value() interface{}

	// Return last error occurred.
	Error() error

	// Set last error
	SetError(error)
}

type RandomAccess

type RandomAccess interface {
	// RandomAccess is a Bounded iterator.
	Bounded

	// Jump to any position in the stream. If the position is less than
	// First position or greater than Last position the method returns
	// an error.
	Goto(int) error

	// Get the length of the data stream.
	Len() int
}

Directories

Path Synopsis
The Higher Order Iterators (hoi) package is a collection of iterators that build on the common interfacs provided by package i and provde higher order functionality.
The Higher Order Iterators (hoi) package is a collection of iterators that build on the common interfacs provided by package i and provde higher order functionality.
The Iterator Containers (icon) package provides iterators that give access to containers such as slices.
The Iterator Containers (icon) package provides iterators that give access to containers such as slices.
The Iterator Generators (igen) package contains few iterators that act as generators.
The Iterator Generators (igen) package contains few iterators that act as generators.
The Iterator Testing (itesting) package provides a collection of functions that assist in testing iterators and assert that they fulfill the invariants they most hold to ensure predictable behaviour.
The Iterator Testing (itesting) package provides a collection of functions that assist in testing iterators and assert that they fulfill the invariants they most hold to ensure predictable behaviour.
The Iterator ToolKit package (itk) provides reusable components to help with the construction of iterators.
The Iterator ToolKit package (itk) provides reusable components to help with the construction of iterators.
The Iterator Typed package (ityped) provides typed variants of all iterator interfaces in the i package.
The Iterator Typed package (ityped) provides typed variants of all iterator interfaces in the i package.

Jump to

Keyboard shortcuts

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