Documentation
¶
Overview ¶
Package itertools implements common utilities to work with Go 1.23's iterators.
Index ¶
- func All[V any](seq iter.Seq[V], p func(V) bool) bool
- func Any[V any](seq iter.Seq[V], p func(V) bool) bool
- func Chain[V any](seq1, seq2 iter.Seq[V]) iter.Seq[V]
- func ChunkBy[V any, K comparable](seq iter.Seq[V], key func(V) K) iter.Seq[iter.Seq[V]]
- func Chunks[V any](seq iter.Seq[V], s uint) iter.Seq[iter.Seq[V]]
- func Cycle[V any](seq iter.Seq[V]) iter.Seq[V]
- func Drop[V any](seq iter.Seq[V], n uint) iter.Seq[V]
- func DropWhile[V any](seq iter.Seq[V], p func(V) bool) iter.Seq[V]
- func Filter[V any](seq iter.Seq[V], p func(V) bool) iter.Seq[V]
- func Flatten[V any](seq iter.Seq[iter.Seq[V]]) iter.Seq[V]
- func FromMap[K comparable, V any](m map[K]V) iter.Seq2[K, V]
- func FromSlice[V any](vs []V) iter.Seq[V]
- func InterleaveLongest[V any](seq1, seq2 iter.Seq[V]) iter.Seq[V]
- func InterleaveShortest[V any](seq1, seq2 iter.Seq[V]) iter.Seq[V]
- func IsSorted[V cmp.Ordered](seq iter.Seq[V]) bool
- func IsSortedFunc[V any](seq iter.Seq[V], cmp func(V, V) int) bool
- func Map[V any, W any](seq iter.Seq[V], f func(V) W) iter.Seq[W]
- func MapFromSeq2[V any, W any, X any](seq iter.Seq2[V, W], f func(V, W) X) iter.Seq[X]
- func MapToSeq2[V any, W any, X any](seq iter.Seq[V], f func(V) (W, X)) iter.Seq2[W, X]
- func Max[V cmp.Ordered](seq iter.Seq[V]) (V, bool)
- func MaxFunc[V any](seq iter.Seq[V], cmp func(V, V) int) (V, bool)
- func Min[V cmp.Ordered](seq iter.Seq[V]) (V, bool)
- func MinFunc[V any](seq iter.Seq[V], cmp func(V, V) int) (V, bool)
- func None[V any](seq iter.Seq[V], p func(V) bool) bool
- func Reduce[V any, W any](seq iter.Seq[V], f func(W, V) W, init W) W
- func Repeat[V any](v V) iter.Seq[V]
- func RepeatN[V any](v V, n uint) iter.Seq[V]
- func ReverseSlice[V any](vs []V) iter.Seq[V]
- func Take[V any](seq iter.Seq[V], n uint) iter.Seq[V]
- func TakeWhile[V any](seq iter.Seq[V], p func(V) bool) iter.Seq[V]
- func WithFunc[V any](f func() V) iter.Seq[V]
- func ZipShortest[V, W any](seq1 iter.Seq[V], seq2 iter.Seq[W]) iter.Seq2[V, W]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All reports whether all values yielded by seq pass p. All is short-circuiting, i.e. it will stop when it reaches a value that does not pass p.
func Any ¶
Any reports whether any value yielded by seq passes p. Any is short-circuiting, i.e. it will stop when it reaches a value that passes p.
func Chain ¶
Chain returns an iterator that will first yield all the values from seq1, then all the values from seq2.
func ChunkBy ¶ added in v0.2.0
ChunkBy returns an iterator that groups values from seq according to key and yields those groups. Consecutive elements that map to the same key are assigned to the same group.
func Chunks ¶ added in v0.2.0
Chunks returns an iterator that chunks values from seq into groups of size s.
func Cycle ¶
Cycle returns an iterator that cycles through seq indefinitely. Values from seq are progressively accumulated into a slice during the first cycle, and reused for the next cycles.
func DropWhile ¶
DropWhile returns an iterator that will drop values from seq as long as they pass p. The iterator yields the remaining values when it encounters the first value that does not pass p.
func FromMap ¶ added in v0.2.0
func FromMap[K comparable, V any](m map[K]V) iter.Seq2[K, V]
FromMap returns an iterator yielding all the values from m.
func InterleaveLongest ¶ added in v0.2.0
InterleaveLongest returns an iterator that will yield values from seq1 and seq2 alternatively, starting with seq1. The iterator stops after both seq1 and seq2 are exhausted.
func InterleaveShortest ¶ added in v0.2.0
InterleaveShortest returns an iterator that will yield values from seq1 and seq2 alternatively, starting with seq1. The iterator stops after the iterator whose turn it is to produce a value is exhausted.
func IsSorted ¶ added in v0.2.0
IsSorted reports whether values yielded by seq are sorted in ascending order.
func IsSortedFunc ¶ added in v0.2.0
IsSortedFunc reports whether values yielded by seq are sorted in ascending order, comparing them using cmp.
func MapFromSeq2 ¶ added in v0.2.0
MapFromSeq2 returns an iterator that will yield values from seq after transforming them using f. It is a specialization of Map for when seq is an iter.Seq2 iterator.
func MapToSeq2 ¶ added in v0.2.0
MapToSeq2 returns an iterator that will yield values from seq after transforming them using f. It is a specialization of Map for when the returned iterator is an iter.Seq2 iterator.
func Max ¶
Max returns the minimum value yielded by seq. If no values are yielded by seq, a zero-value is returned and the second return value is false. If there is more than one minimal element according to the cmp function, Max returns the first one.
func MaxFunc ¶
MaxFunc returns the minimum value yielded by seq, comparing values using cmp. If no values are yielded by seq, a zero-value is returned and the second return value is false. If there is more than one minimal element according to the cmp function, MaxFunc returns the first one.
func Min ¶
Min returns the minimum value yielded by seq. If no values are yielded by seq, a zero-value is returned and the second return value is false. If there is more than one minimal element according to the cmp function, Min returns the first one.
func MinFunc ¶
MinFunc returns the minimum value yielded by seq, comparing values using cmp. If no values are yielded by seq, a zero-value is returned and the second return value is false. If there is more than one minimal element according to the cmp function, MinFunc returns the first one.
func None ¶
None reports whether no value yielded by seq passes p. None is short-circuiting, i.e. it will stop when it reaches a value that passes p.
func Reduce ¶ added in v0.2.0
Reduce reduces the values yielded by seq to a single one by repeatedly applying f.
func RepeatN ¶
RepeatN works like Repeat, but returns an iterator that stops after yielding n values.
func ReverseSlice ¶ added in v0.2.0
ReverseSlice returns an iterator that will yield values from vs in reversed order/
func TakeWhile ¶
TakeWhile returns an iterator that will yield values from seq as long as they pass p. The iterator stops when it encounters a value that does not pass p.
Types ¶
This section is empty.