Documentation ¶
Index ¶
- func Count[T any](i Iterator[T]) int
- func Fold[Acc, T any](i Iterator[T], acc Acc, step func(Acc, T) Acc) Acc
- func Last[T any](i Iterator[T]) (t T, ok bool)
- func Max[T constraints.Ordered](i Iterator[T]) (T, bool)
- func MaxBy[T any](i Iterator[T], less func(a, b T) bool) (T, bool)
- func Min[T constraints.Ordered](i Iterator[T]) (T, bool)
- func MinBy[T any](i Iterator[T], less func(a, b T) bool) (T, bool)
- func Reduce[T any](i Iterator[T], step func(T, T) T) (acc T, ok bool)
- func Sum[T constraints.Integer | constraints.Float | constraints.Complex](i Iterator[T]) T
- type ChanIterator
- type Iterable
- type Iterator
- type SliceIterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Last ¶
Last returns the last value of this iterator, if any exists. If empty, Last returns zero and false.
func Max ¶
func Max[T constraints.Ordered](i Iterator[T]) (T, bool)
Max returns the maximum value and true if the collection was not empty, and zero and false otherwise.
func MaxBy ¶
MaxBy returns the maximum value using the given comparison function and true if the collection was not empty, and zero and false otherwise.
func Min ¶
func Min[T constraints.Ordered](i Iterator[T]) (T, bool)
Min returns the minimum value and true if the collection was not empty, and zero and false otherwise.
func MinBy ¶
MinBy returns the minimum value using the given comparison function and true if the collection was not empty, and zero and false otherwise.
func Reduce ¶
Reduce accumulates a value by applying the step function to the accumulated value and the next element. This is a specialized version of Fold, and returns a boolean value which is false if the collection was empty.
func Sum ¶
func Sum[T constraints.Integer | constraints.Float | constraints.Complex](i Iterator[T]) T
Sum returns the sum of elements in the iterator. This consumes the iterator.
Types ¶
type ChanIterator ¶
type ChanIterator[T any] chan T
ChanIterator is an iterator backed by a channel.
func (ChanIterator[T]) EstimatedRemaining ¶
func (c ChanIterator[T]) EstimatedRemaining() int
type Iterator ¶
type Iterator[T any] interface { // Next returns the next element, or a zero element and false if there are no more elements Next() (T, bool) // Advance moves the iterator forward by n elements, returning how much it was actually able to progress. Advance(n int) int // EstimatedRemaining returns a lower bound on the number of elements remaining, // i.e. there are at least Remaining() elements remaining. // WARNING: This is a *lower* bound! There may be more elements, even if this returns zero! EstimatedRemaining() int // Collect returns a slice containing the elements of the iterator. Collect() []T }
Iterator represents a one-time one-by-one view of elements through some internal state.
func FromChannel ¶
FromChannel creates a new iterator which iterates over the channel `c`
type SliceIterator ¶
type SliceIterator[T any] struct { // contains filtered or unexported fields }
SliceIterator enables iteration over slices.
func (*SliceIterator[T]) Advance ¶
func (s *SliceIterator[T]) Advance(n int) int
func (*SliceIterator[T]) Collect ¶
func (s *SliceIterator[T]) Collect() []T
func (*SliceIterator[T]) EstimatedRemaining ¶
func (s *SliceIterator[T]) EstimatedRemaining() int
func (*SliceIterator[T]) Next ¶
func (s *SliceIterator[T]) Next() (out T, ok bool)
func (*SliceIterator[T]) Reset ¶
func (s *SliceIterator[T]) Reset()