Documentation ¶
Overview ¶
Package iters defines the general iterator interface and provides different operations on top of them.
Index ¶
- func Advance[T any](it Iterator[T], n uint)
- func Equal[T comparable](it1, it2 Iterator[T]) bool
- func EqualFunc[T1 any, T2 any](it1 Iterator[T1], it2 Iterator[T2], eq gcl.EqualFn[T1, T2]) bool
- func Find[T any](it Iterator[T], pred func(T) bool) (t T, ok bool)
- func Fold[T any, V any](it Iterator[T], fn func(V, T) V, init V) (acc V)
- func ForEach[T any](it Iterator[T], fn func(T))
- func Max[T constraints.Ordered](it Iterator[T]) (max T)
- func MaxFunc[T any](it Iterator[T], less gcl.LessFn[T]) (max T)
- func Min[T constraints.Ordered](it Iterator[T]) (min T)
- func MinFunc[T constraints.Ordered](it Iterator[T], less gcl.LessFn[T]) (min T)
- func Reduce[T any](it Iterator[T], fn func(T, T) T) (acc T)
- func Sum[T gcl.Number](it Iterator[T]) (sum T)
- type Iterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Advance ¶
Advance advances an iterator n steps. Advance stops at any point where the given iterator doesn't have a next element.
func Equal ¶
func Equal[T comparable](it1, it2 Iterator[T]) bool
Equal determines if the elements of two iterators are equal. It returns true if all elements are equal and both iterators have the same number of elements. If the first iterator has l1 elements and the second iterator has l2 elements, Equal advances each iterator min(l1, l2) steps.
func EqualFunc ¶
EqualFunc works the same as Equal, but it uses the function eq for element comparison.
func Find ¶
Find returns the first element in an iterator that satisfies pred. The returned boolean value indicates if such an element exists. If a satisfying element exists, the given iterator it advances the first satisfying element by one step, otherwise Find moves the iterator it to its end.
func Fold ¶
Fold applies a function of two arguments cumulatively to the items of the given iterator from the beginning to the end. Fold gives an initial value and start its operation by using the initial value. Fold moves the given iterator it to its end such that after a Fold call it.HasNext() will be false.
func ForEach ¶
ForEach calls a function on each element of an iterator. ForEach moves the given iterator it to its end such that after a ForEach call it.HasNext() will be false.
func Max ¶
func Max[T constraints.Ordered](it Iterator[T]) (max T)
Max returns the maximum element in an iterator of any ordered type. Max moves the given iterator it to its end such that after a Max call it.HasNext() will be false.
func MaxFunc ¶
MaxFunc returns the maximum element in an iterator and uses the given less function for comparison. MaxFunc moves the given iterator it to its end such that after a MaxFunc call it.HasNext() will be false.
func Min ¶
func Min[T constraints.Ordered](it Iterator[T]) (min T)
Min returns the minimum element in an iterator of any ordered type. Min moves the given iterator it to its end such that after a Min call it.HasNext() will be false.
func MinFunc ¶
func MinFunc[T constraints.Ordered](it Iterator[T], less gcl.LessFn[T]) (min T)
MinFunc returns the minimum element in an iterator and uses the given less function for comparison. MinFunc moves the given iterator it to its end such that after a MinFunc call it.HasNext() will be false.
Types ¶
type Iterator ¶
type Iterator[T any] interface { // HasNext tests whether the iterator can advance. HasNext() bool // Next advances the iterator and returns the next value in iteration. Next() T }
Iterator defines the general iterator interface. Iterator makes it possible to iterate over collections.
func Filter ¶
Filter filters elements of an iterator that satisfy the pred. Filter returns an iterator over the filtered elements. Filter moves the given iterator it to its end such that after a Filter call it.HasNext() will be false. Filter is lazy, in a way that if you don't consume the returned iterator nothing will happen.
func Map ¶
Map applies the function fn on elements the given iterator it and returns a new iterator over the mapped values. Map moves the given iterator it to its end such that after a Map call it.HasNext() will be false. Map is lazy, in a way that if you don't consume the returned iterator nothing will happen.