Documentation ¶
Overview ¶
Package itlib provides generic function for operating on iterators.
Index ¶
- func Apply[T any](it itkit.Iterator[T], fn ApplyFn[T])
- func ApplyN[T any](it itkit.Iterator[T], fn ApplyNFn[T])
- func ApplyTo[T, R any](it itkit.Iterator[T], obj R, fn ApplyToFn[T, R]) R
- func ChainI[T any](iters itkit.Iterator[itkit.Iterator[T]]) itkit.Iterator[T]
- func ChainV[T any](iters ...itkit.Iterator[T]) itkit.Iterator[T]
- func Each[T any](it itkit.Iterator[T], fn EachFn[T])
- func EachN[T any](it itkit.Iterator[T], fn EachNFn[T])
- func Empty[T any]() itkit.Iterator[T]
- func Filter[T any](it itkit.Iterator[T], cb FilterFn[T]) itkit.Iterator[T]
- func Find[T any](it itkit.Iterator[T], fn EqualFn[T], needle T) (out T, ok bool)
- func Head[T any](it itkit.Iterator[T]) (out T, ok bool)
- func HeadOrElse[T any](it itkit.Iterator[T], v T) T
- func Map[T, V any](it itkit.Iterator[T], fn MapFn[T, V]) itkit.Iterator[V]
- func Reduce[T, R any](it itkit.Iterator[T], fn AccumulatorFn[T, R]) (out R)
- func ReduceWithInitial[T, R any](initial R, it itkit.Iterator[T], fn AccumulatorFn[T, R]) (out R)
- func Sum[T constraints.Ordered](it itkit.Iterator[T]) T
- func SumWithInitial[T constraints.Ordered](initial T, it itkit.Iterator[T]) T
- func Zip[T1, T2 any](it1 itkit.Iterator[T1], it2 itkit.Iterator[T2]) itkit.Iterator[Pair[T1, T2]]
- type AccumulatorFn
- type ApplyFn
- type ApplyNFn
- type ApplyToFn
- type ChainIterator
- type EachFn
- type EachNFn
- type EmptyIterator
- type EqualFn
- type FilterFn
- type FilterIter
- type MapFn
- type MapIterator
- type Pair
- type ZipIterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyN ¶
ApplyN walks through the given Iterator it and calls ApplyNFn fn for every single entry together with its index.
func ApplyTo ¶
ApplyTo walks through the given Iterator it and calls ApplyToFn fn for every single entry with the given value in obj of type R, returning the passed value.
ApplyTo behaves like ReduceWithInitial with the exception that the result of the callback for the previous iteration not being passed down to the next iteration.
func Each ¶
Each walks through the given Iterator it and calls EachFn fn for every single entry, aborting if EachFn fn returns true.
func EachN ¶
EachN walks through the given Iterator it and calls EachNFn fn for every single entry together with its index, aborting if the given function returns true.
func Filter ¶
Filter returns an Iterator yielding items from the given iterator for which the given FilterFn function returns true.
func Head ¶ added in v0.7.0
Head returns the next value in the iterator and true, if the iterator has a next item, consuming it from the iterator as well. Returns the zero value and false otherwise.
func HeadOrElse ¶ added in v0.7.0
HeadOrElse returns the next value in the iterator, if the iterator has a next item, consuming it from the iterator. Returns the provided default value otherwise.
func Map ¶
Map returns an iterator that applies MapFn function to every item of iterkit.Iterator iterable, yielding the results.
func Reduce ¶
func Reduce[T, R any](it itkit.Iterator[T], fn AccumulatorFn[T, R]) (out R)
Reduce reduces the given Iterator to a value which is the accumulated result of running each value through AccumulatorFn, where each successive invocation of AccumulatorFn is supplied the return value of the previous invocation.
func ReduceWithInitial ¶
func ReduceWithInitial[T, R any](initial R, it itkit.Iterator[T], fn AccumulatorFn[T, R]) (out R)
ReduceWithInitial reduces the given Iterator to a value which is the accumulated result of running each value through AccumulatorFn, where each successive invocation of AccumulatorFn is supplied the return value of the previous invocation.
func Sum ¶
func Sum[T constraints.Ordered](it itkit.Iterator[T]) T
Sum accumulates the Iterator values based on the summation of their values.
func SumWithInitial ¶
func SumWithInitial[T constraints.Ordered](initial T, it itkit.Iterator[T]) T
SumWithInitial accumulates the Iterator values based on the summation of their values.
Types ¶
type AccumulatorFn ¶
type AccumulatorFn[T, R any] func(R, T) R
type ChainIterator ¶
type ChainIterator[T any] struct { // contains filtered or unexported fields }
ChainIterator chains multiple Iterator iterators together, traversing the given iterators until they are exhausted and proceeding with the next iterator.
func (*ChainIterator[T]) Next ¶
func (c *ChainIterator[T]) Next() bool
func (*ChainIterator[T]) Value ¶
func (c *ChainIterator[T]) Value() T
type EmptyIterator ¶
type EmptyIterator[T any] struct{}
func (EmptyIterator[T]) Next ¶
func (e EmptyIterator[T]) Next() bool
func (EmptyIterator[T]) Value ¶
func (e EmptyIterator[T]) Value() (v T)
type FilterIter ¶
type FilterIter[T any] struct { // contains filtered or unexported fields }
func (*FilterIter[T]) Next ¶
func (f *FilterIter[T]) Next() bool
func (*FilterIter[T]) Value ¶
func (f *FilterIter[T]) Value() T
type MapIterator ¶
type MapIterator[T, V any] struct { // contains filtered or unexported fields }
func (*MapIterator[T, V]) Next ¶
func (m *MapIterator[T, V]) Next() (ok bool)
func (*MapIterator[T, V]) Value ¶
func (m *MapIterator[T, V]) Value() V
type ZipIterator ¶
type ZipIterator[T1, T2 any] struct { Left itkit.Iterator[T1] Right itkit.Iterator[T2] // contains filtered or unexported fields }
func (*ZipIterator[T1, T2]) Next ¶
func (it *ZipIterator[T1, T2]) Next() (ok bool)
func (*ZipIterator[T1, T2]) Value ¶
func (it *ZipIterator[T1, T2]) Value() Pair[T1, T2]