Documentation
¶
Overview ¶
Package itertools provides utility functions to work with iterators.
Index ¶
- func Concat[Slice []T, T any](seqs ...Slice) iter.Seq[T]
- func ConcatIter[T any](seqs ...iter.Seq[T]) iter.Seq[T]
- func Filter[Slice []T, T comparable](seq Slice, filterFn func(T) bool) iter.Seq[T]
- func ForEach[T any](seq iter.Seq[T], fn func(int, T))
- func Map[Slice []T, T any](seq Slice, mapFn func(int, T) T) iter.Seq2[int, T]
- func Reduce[T any](seq iter.Seq[T], reducer func(acc T, cur T) T, init T) T
- func Reverse[Slice []T, T any](seqs ...Slice) iter.Seq[T]
- func Shuffle[Slice []T, T any](seq Slice) iter.Seq[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Concat ¶
Concat receives an arbitrary number of slices and returns an iterator to iterate on them successively, in the order they are given.
func ConcatIter ¶
ConcatIter receives an arbitrary number of slices and returns an iterator to iterate over the elements, in the order they are given.
func Filter ¶
func Filter[Slice []T, T comparable](seq Slice, filterFn func(T) bool) iter.Seq[T]
Filter returns an iterator that contains the elements of seq for which filterFn returns true.
func ForEach ¶
ForEach executes a user-supplied function on each element of the sequence. It does not return any output.
func Map ¶
Map executes a user-supplied function on each element of the slice and returns an iterator over modified elements.
func Reduce ¶
Reduce executes a user-supplied "reducer" function on each element of the array, in order, passing in the return value from the calculation on the preceding element.
func Reverse ¶
Reverse receives an arbitrary number of slices and returns an iterator to iterate over the elements, in the reverse order they are given.
For example, given the input:
Reverse([]int{10, 20, 30}, []int{40, 50, 60})
The iterator following the output:
{60, 50, 40, 30, 20, 10}
func Shuffle ¶
Shuffle receives a slice and returns an iterator over its shuffled elements.
Note: In order not to allocate extra memory, it shuffles given slice(array) in place. If you need the original slice(array) untouched, you can clone your slice using slices.Clone and then pass it as the argument.
Types ¶
This section is empty.