Documentation ¶
Index ¶
- func Reduce[T any, U any](iter Iterator[T], initial U, reducer func(U, T) U) U
- func ToChannel[T any](ctx context.Context, iter Iterator[T], buffer int) <-chan T
- func ToSlice[T any](iter Iterator[T]) []T
- type DeleteIterator
- type Iterator
- func Filter[T any](iter Iterator[T], predicateFunc func(item T) bool) Iterator[T]
- func FromChannel[T any](channel <-chan T) Iterator[T]
- func FromRange[T constraints.Integer | constraints.Float](start, end, step T) Iterator[T]
- func FromSlice[T any](slice []T) Iterator[T]
- func Join[T any](iters ...Iterator[T]) Iterator[T]
- func Map[T any, U any](iter Iterator[T], iteratee func(item T) U) Iterator[U]
- func Take[T any](it Iterator[T], num int) Iterator[T]
- type PrevIterator
- type SetIterator
- type StopIterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DeleteIterator ¶
type DeleteIterator[T any] interface { Iterator[T] // Delete deletes the current iterator element; // that is, the one returned by the last call to Next. // Delete should panic if called before Next or after // Next returns false. Delete() }
DeleteIter is an Iter that implements a Delete method.
type Iterator ¶
type Iterator[T any] interface { // HasNext checks if there is a next value in the iteration or not HasNext() bool // Next returns the next value in the iteration if there is one, // and reports whether the returned value is valid. // Once Next returns ok==false, the iteration is over, // and all subsequent calls will return ok==false. Next() (item T, ok bool) }
Iterator supports iterating over a sequence of values of type `E`.
func Filter ¶
Filter creates a new iterator that returns only the items that pass specified predicate function.
func FromChannel ¶
FromChannel creates a iterator which returns the numeric range between start inclusive and end exclusive by the step size. start should be less than end, step shoud be positive.
func FromRange ¶
func FromRange[T constraints.Integer | constraints.Float](start, end, step T) Iterator[T]
FromRange creates a iterator which returns the numeric range between start inclusive and end exclusive by the step size. start should be less than end, step shoud be positive.
func Join ¶
Join creates an iterator that join all elements of iters[0], then all elements of iters[1] and so on.
type PrevIterator ¶
type PrevIterator[T any] interface { Iterator[T] // Prev moves the iterator to the previous position. // After calling Prev, Next will return the value at // that position in the container. For example, after // it.Next() returning (v, true) // it.Prev() // another call to it.Next will again return (v, true). // Calling Prev before calling Next may panic. // Calling Prev after Next returns false will move // to the last element, or, if there are no elements, // to the iterator's initial state. Prev() }
PrevIterator is an iterator with a Prev method.
type SetIterator ¶
type SetIterator[T any] interface { Iterator[T] // Set replaces the current iterator element with v. // Set should panic if called before Next or after // Next returns false. Set(v T) }
SetIterator is an Iter that implements a Set method.
type StopIterator ¶
type StopIterator[T any] interface { Iterator[T] // Stop indicates that the iterator will no longer be used. // After a call to Stop, future calls to Next may panic. // Stop may be called multiple times; // all calls after the first will have no effect. Stop() }
StopIterator is an interface for stopping Iterator.