Documentation
¶
Index ¶
- func Fold[V any, T any](it *Iterator[V], transform func(T, V) T, initial T) T
- func Product[V any, T Productable](it *Iterator[V], transform func(V) T, one T) T
- func Sum[V any, T cmp.Ordered](it *Iterator[V], transform func(V) T, zero T) T
- type Iterator
- func CartesianProduct[A, B any](it1 *Iterator[A], it2 *Iterator[B]) ...
- func ChunkList[V any](it *Iterator[V], size int) []*Iterator[V]
- func ChunkSlice[V any](it *Iterator[V], size int) *Iterator[[]V]
- func Chunks[V any](it *Iterator[V], size int) *Iterator[*Iterator[V]]
- func Flatten[V any](its ...*Iterator[V]) *Iterator[V]
- func NewIterator[V any](v ...V) *Iterator[V]
- func Repeat[V any](v V, n int) *Iterator[V]
- func ToIter[V any](slice []V) *Iterator[V]
- func Zip[A, B any](it1 *Iterator[A], it2 *Iterator[B]) ...
- func Zip2[A, B any](it1 *Iterator[A], it2 *Iterator[B], _ struct{ ... }) ...
- func (it *Iterator[V]) All(predicate func(V) bool) bool
- func (it *Iterator[V]) Any(predicate func(V) bool) bool
- func (it *Iterator[V]) AssertEq(expected []V, predicate func(V, V) bool) bool
- func (it *Iterator[V]) Chain(other *Iterator[V]) *Iterator[V]
- func (it *Iterator[V]) Collect() []V
- func (it *Iterator[V]) Compact() *Iterator[V]
- func (it *Iterator[V]) CompactWith(zero V) *Iterator[V]
- func (it *Iterator[V]) Count() int
- func (it *Iterator[V]) Current() V
- func (it *Iterator[V]) Cycle() *Iterator[V]
- func (it *Iterator[V]) Difference(other *Iterator[V], keyFunc func(V) any) *Iterator[V]
- func (it *Iterator[V]) Drop(n int) *Iterator[V]
- func (it *Iterator[V]) DropWhile(predicate func(V) bool) *Iterator[V]
- func (it *Iterator[V]) Each(f func(V))
- func (it *Iterator[V]) Filter(predicate func(V) bool) *Iterator[V]
- func (it *Iterator[V]) Find(predicate func(V) bool) (V, bool)
- func (it *Iterator[V]) First() V
- func (it *Iterator[V]) GroupBy(keyFunc func(V) string) map[string][]V
- func (it *Iterator[V]) Index(predicate func(V) bool) int
- func (it *Iterator[V]) Intersection(other *Iterator[V], keyFunc func(V) any) *Iterator[V]
- func (it *Iterator[V]) IsSorted(less func(a, b V) bool) bool
- func (it *Iterator[V]) Last() V
- func (it *Iterator[V]) LastIndex(predicate func(V) bool) int
- func (it *Iterator[V]) Map(f func(V) V) *Iterator[V]
- func (it *Iterator[V]) Max(less func(a, b V) bool) (V, bool)
- func (it *Iterator[V]) Min(less func(a, b V) bool) (V, bool)
- func (it *Iterator[V]) Next() bool
- func (it *Iterator[V]) Nth(n int) V
- func (it *Iterator[V]) Partition(predicate func(V) bool) (matched *Iterator[V], unmatched *Iterator[V])
- func (it *Iterator[V]) Replace(predicate func(V) bool, replacement V) *Iterator[V]
- func (it *Iterator[V]) ReplaceAll(replacement V) *Iterator[V]
- func (it *Iterator[V]) Reverse() *Iterator[V]
- func (it *Iterator[V]) Shuffle() *Iterator[V]
- func (it *Iterator[V]) Sort(less func(a, b V) bool) *Iterator[V]
- func (it *Iterator[V]) StepBy(n int) *Iterator[V]
- func (it *Iterator[V]) String() string
- func (it *Iterator[V]) Take(n int) *Iterator[V]
- func (it *Iterator[V]) TakeWhile(predicate func(V) bool) *Iterator[V]
- func (it *Iterator[V]) ToLower() *Iterator[V]
- func (it *Iterator[V]) ToUpper() *Iterator[V]
- func (it *Iterator[V]) TrimSpace() *Iterator[V]
- func (it *Iterator[V]) Union(other *Iterator[V], keyFunc func(V) any) *Iterator[V]
- func (it *Iterator[V]) Unique(keyFunc func(V) any) *Iterator[V]
- type Productable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Product ¶
func Product[V any, T Productable](it *Iterator[V], transform func(V) T, one T) T
Product multiplies all elements of the iterator
Types ¶
type Iterator ¶
type Iterator[V any] struct { // contains filtered or unexported fields }
Iterator is a generic iterator that can be used to iterate over any type of sequence
func CartesianProduct ¶
CartesianProduct returns an iterator of all pairs of elements from two iterators
func ChunkSlice ¶
ChunkSlice returns an Iterator of slices of the given size
func NewIterator ¶
NewIterator creates a new iterator from a sequence function
func Zip2 ¶
func Zip2[A, B any](it1 *Iterator[A], it2 *Iterator[B], _ struct { First A Second B }) *Iterator[struct { First A Second B }]
Zip2 combines two iterators element-wise into a single iterator of pairs. If one iterator is longer than the other, the shorter iterator is extended with the fill value.
func (*Iterator[V]) AssertEq ¶
AssertEq asserts that the elements in the Iterator are equal to the expected elements
func (*Iterator[V]) Collect ¶
func (it *Iterator[V]) Collect() []V
Collect collects all elements from the Iterator into a slice.
func (*Iterator[V]) CompactWith ¶
CompactWith removes the elements that are equal to the zero value of the type
func (*Iterator[V]) Current ¶
func (it *Iterator[V]) Current() V
Current returns the current element of the iterator
func (*Iterator[V]) Cycle ¶
Cycle returns an Iterator that cycles through the elements of the Iterator indefinitely
func (*Iterator[V]) Difference ¶
Difference returns an Iterator that yields elements that are present in the first iterator but not in the second
func (*Iterator[V]) DropWhile ¶
DropWhile returns an Iterator that skips elements while the predicate is true
func (*Iterator[V]) Each ¶
func (it *Iterator[V]) Each(f func(V))
Each applies a function to each element of the Iterator.
func (*Iterator[V]) Filter ¶
Filter returns an Iterator that only yields elements that satisfy the predicate
func (*Iterator[V]) First ¶
func (it *Iterator[V]) First() V
First returns the first element of the Iterator
func (*Iterator[V]) Index ¶
Index returns the index of the first element that satisfies the predicate
func (*Iterator[V]) Intersection ¶
Intersection returns an Iterator that yields elements that are present in both iterators
func (*Iterator[V]) IsSorted ¶
IsSorted returns true if the elements in the Iterator are sorted in ascending order
func (*Iterator[V]) Last ¶
func (it *Iterator[V]) Last() V
Last returns the last element of the Iterator
func (*Iterator[V]) LastIndex ¶
LastIndex returns the index of the last element that satisfies the predicate
func (*Iterator[V]) Max ¶
Max returns the maximum element in the Iterator using the provided less function
func (*Iterator[V]) Min ¶
Min returns the minimum element in the Iterator using the provided less function
func (*Iterator[V]) Partition ¶
func (it *Iterator[V]) Partition(predicate func(V) bool) (matched *Iterator[V], unmatched *Iterator[V])
Partition returns two Iterators, one with elements that satisfy the predicate and one with elements that don't
func (*Iterator[V]) Replace ¶
Replace replaces all elements that satisfy the predicate with the replacement
func (*Iterator[V]) ReplaceAll ¶
ReplaceAll replaces all elements with the replacement
func (*Iterator[V]) Reverse ¶
Reverse returns an Iterator that iterates over the elements in reverse order
func (*Iterator[V]) Sort ¶
Sort returns an Iterator with elements sorted in ascending order using the provided less function.
func (*Iterator[V]) Take ¶
Take returns an Iterator that yields the first n elements of the Iterator
func (*Iterator[V]) TakeWhile ¶
TakeWhile returns an Iterator that yields elements while the predicate is true
func (*Iterator[V]) ToLower ¶
ToLower converts all elements to lowercase if they are strings and if not, it leaves them unchanged in the Iterator
func (*Iterator[V]) ToUpper ¶
ToUpper converts all elements to uppercase if they are strings and if not, it leaves them unchanged in the Iterator
func (*Iterator[V]) TrimSpace ¶
TrimSpace trims the whitespace from all elements if they are strings and if not, it leaves them unchanged in the Iterator
type Productable ¶
type Productable interface { constraints.Integer | constraints.Float | constraints.Complex }