Documentation
¶
Overview ¶
package it provides some tools for working with iterators, inspired by Python's itertools.
Index ¶
- func All(bs iter.Seq[bool]) bool
- func Batch[A any](i iter.Seq[A], n int) iter.Seq[[]A]
- func Chain[A any](its ...iter.Seq[A]) iter.Seq[A]
- func CollectErr[A any](i iter.Seq2[A, error]) ([]A, error)
- func Concat[A any](its iter.Seq[iter.Seq[A]]) iter.Seq[A]
- func Const[A any](a A) iter.Seq[A]
- func Enumerate[A any](it iter.Seq[A]) iter.Seq2[int, A]
- func Filter[A any](it iter.Seq[A], p func(A) bool) iter.Seq[A]
- func Fold[A, B any](it iter.Seq[A], z B, f func(A, B) B) B
- func Limit[A any](i iter.Seq[A], n int) iter.Seq[A]
- func Map[A, B any](as iter.Seq[A], f func(A) B) iter.Seq[B]
- func Map1x2[A, B, C any](as iter.Seq[A], f func(A) (B, C)) iter.Seq2[B, C]
- func Map2x1[A, B, C any](abs iter.Seq2[A, B], f func(A, B) C) iter.Seq[C]
- func Map2x2[A, B, C, D any](abs iter.Seq2[A, B], f func(A, B) (C, D)) iter.Seq2[C, D]
- func Perm[E any, S ~[]E](data S) iter.Seq[S]
- func Take[A any](it iter.Seq[A], n int) iter.Seq[A]
- func TakeWhile[A any](it iter.Seq[A], p func(A) bool) iter.Seq[A]
- func Unpair[A, B any](i iter.Seq[Pair[A, B]]) iter.Seq2[A, B]
- func Zip[A, B any](as iter.Seq[A], bs iter.Seq[B]) iter.Seq2[A, B]
- type Pair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All is a specialised fold for iterators of bools that returns true iff all of the values yielded by the iterator are true.
func Batch ¶ added in v0.0.2
Batch returns an iterator that yields batches of n consecutive values from the provided iterator. The last batch may be smaller. The yielded slice is only valid until the next value is yields (it is reused between batches).
func Chain ¶
Chain takes a number of iterators and returns a single iterator that yields of the values from all of the iterators in sequence, starting with the first argument, then the second and so on.
func CollectErr ¶ added in v0.0.4
CollectErr collects all of the A elements from the iterator, up until the first non-nil error. When a non-nil error is encountered it is immediately returned, along with with any values successfully retrieved up to that point. Note that any value returned alongside the error will _not_ be returned; the assumption is that the iterator either returns an error or a value and not both.
func Const ¶
Const returns an iterator that continually yields the provided value, forever. Note that this is an infinite iterator, intended to be used with something like Zip or Take that will stop early.
func Enumerate ¶ added in v0.0.2
Enumerate returns an iterator that pairs each element in the provided sequence with its index in the sequence, starting from 0.
func Filter ¶
Filter returns an iterator which yields only those values in it for which p returns true.
func Fold ¶
Fold performs a left fold across the iterator using the provided combining function and initial value.
func Limit ¶ added in v0.0.2
Limit returns a new iterator that yields the first n values from the provided iterator and then stops. If the parent iterator has fewer than n values, the returned child iterator will just stop when it runs out.
func Map1x2 ¶
Map1x2 maps an iter.Seq to an iter.Seq2 by applying the provided function to each item in turn.
func Map2x1 ¶
Map2x1 maps an iter.Seq2 to an iter.Seq by applying the provided function to each pair of items in turn.
func Map2x2 ¶
Map2x2 maps an iter.Seq2 to an iter.Seq2 by applying the provided function to each pair of items in turn.
func Perm ¶ added in v0.0.3
Perm returns an iterator that yields all permutations of the provided slice. It shuffles the objects in place, and always yields the same slice, so care must be taken if re-using the yielded values.
func Take ¶
Take returns an iterator that yields at most the first n elements of the provided iterator and then stops.
func TakeWhile ¶
TakeWhile returns an iterator that yields the (possibly empty) prefix of the provided iterator for which the given predicate returns true. The returned iterator finishes as soon as it yields a value for which p returns false.
Types ¶
type Pair ¶
type Pair[A, B any] struct { A A B B }
Pair is just a pair of two elements, for occasions where we need to do things like collect the values in an iter.Seq2.
func Collect2 ¶
Collect2 is like slices.Collect, but works with iter.Seq2, returning all of the results as Pairs.