Documentation
¶
Overview ¶
Package transform provides functions transforming iterators.
Index ¶
- func Concat[T any](iterators ...iter.Seq[T]) iter.Seq[T]
- func Concat2[S, T any](iterators ...iter.Seq2[S, T]) iter.Seq2[S, T]
- func Keys[K, V any](iterator iter.Seq2[K, V]) iter.Seq[K]
- func Map[S, T any](iterator iter.Seq[S], f func(S) T) iter.Seq[T]
- func Map2[S, T, U, V any](iterator iter.Seq2[S, T], f func(S, T) (U, V)) iter.Seq2[U, V]
- func MapIn[S, T, U any](iterator iter.Seq2[S, T], f func(S, T) U) iter.Seq[U]
- func MapOut[S, T, U any](iterator iter.Seq[S], f func(S) (T, U)) iter.Seq2[T, U]
- func Resize[T any](iterator iter.Seq[T], size int) iter.Seq[T]
- func Resize2[S, T any](iterator iter.Seq2[S, T], size int) iter.Seq2[S, T]
- func Select[T any](iterator iter.Seq[T], f func(T) bool) iter.Seq[T]
- func Select2[K, V any](iterator iter.Seq2[K, V], f func(K, V) bool) iter.Seq2[K, V]
- func SelectMap[S, T any](iterator iter.Seq[S], f func(S) (T, bool)) iter.Seq[T]
- func SelectMap2[S, T, U, V any](iterator iter.Seq2[S, T], f func(S, T) (U, V, bool)) iter.Seq2[U, V]
- func SelectMapIn[S, T, U any](iterator iter.Seq2[S, T], f func(S, T) (U, bool)) iter.Seq[U]
- func SelectMapOut[S, T, U any](iterator iter.Seq[S], f func(S) (T, U, bool)) iter.Seq2[T, U]
- func Skip[T any](iterator iter.Seq[T], skip int) iter.Seq[T]
- func Skip2[S, T any](iterator iter.Seq2[S, T], skip int) iter.Seq2[S, T]
- func Swap[S, T any](iterator iter.Seq2[S, T]) iter.Seq2[T, S]
- func Values[K, V any](iterator iter.Seq2[K, V]) iter.Seq[V]
- func Zip[S, T any](lhs iter.Seq[S], rhs iter.Seq[T]) iter.Seq2[S, T]
- func ZipAll[S, T any](lhs iter.Seq[S], rhs iter.Seq[T]) iter.Seq2[S, T]
- func ZipIndex[T any](iterator iter.Seq[T]) iter.Seq2[int, T]
- func ZipLeft[S, T any](lhs iter.Seq[S], rhs iter.Seq[T]) iter.Seq2[S, T]
- func ZipRight[S, T any](lhs iter.Seq[S], rhs iter.Seq[T]) iter.Seq2[S, T]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Concat ¶
Concat returns a single iterator concatenating the passed in iterators.
Example ¶
package main import ( "fmt" "slices" "github.com/goaux/iter/transform" ) func main() { got := slices.Collect( transform.Concat( slices.Values([]int{1, 2}), slices.Values([]int{3, 4, 5}), slices.Values([]int{6}), ), ) fmt.Println(got) }
Output: [1 2 3 4 5 6]
func Concat2 ¶
Concat2 returns a single iterator concatenating the passed in iterators.
Example ¶
package main import ( "fmt" "maps" "slices" "github.com/goaux/iter/transform" ) func main() { got := maps.Collect( transform.Concat2( transform.Zip( slices.Values([]int{1, 2, 3}), slices.Values([]string{"a", "b", "c"}), ), transform.Zip( slices.Values([]int{4, 5}), slices.Values([]string{"d", "e"}), ), transform.Zip( slices.Values([]int{6}), slices.Values([]string{"f"}), ), ), ) fmt.Println(got) }
Output: map[1:a 2:b 3:c 4:d 5:e 6:f]
func Map2 ¶
Map2 transforms iter.Seq2[S, T] to iter.Seq2[U, V] using f, which transforms S and T to U and V.
func MapIn ¶
MapIn transforms iter.Seq2[S, T] to iter.Seq[U] using f, which transforms S and T to U.
func MapOut ¶
MapOut transforms iter.Seq[S] to iter.Seq2[T, U] using f, which transforms S to T and U.
func Resize ¶
Resize returns an iterator that changes the number of elements in a sequence. If you specify a size larger than the number of elements in the sequence, the iterator returns zero values for the missing elements. A negative size is considered to be 0.
func Resize2 ¶
Resize2 returns an iterator that changes the number of elements in a sequence. If you specify a size larger than the number of elements in the sequence, the iterator returns zero values for the missing elements. A negative size is considered to be 0.
func Select ¶
Select returns an iterator over sequences of individual values with a condition. When called as seq(yield), seq calls f(v), then yield(v) if f returns true for each value v in the sequence, stopping early if yield returns false.
func Select2 ¶
Select2 returns an iterator over sequences of pairs of values with a condition, most commonly key-value pairs. When called as seq(yield), seq calls f(k, v), then if f returns true calls yield(k, v) for each pair (k, v) in the sequence, stopping early if yield returns false.
func SelectMap ¶ added in v1.2.0
SelectMap provides functionality that combines the functions of Select and Map.
func SelectMap2 ¶ added in v1.2.0
func SelectMap2[S, T, U, V any](iterator iter.Seq2[S, T], f func(S, T) (U, V, bool)) iter.Seq2[U, V]
SelectMap2 provides functionality that combines the functions of Select2 and Map2.
func SelectMapIn ¶ added in v1.2.0
SelectMapIn provides functionality that combines the function of Select2 and MapIn.
func SelectMapOut ¶ added in v1.2.0
SelectMapOut provides functionality that combines the function of Select and MapOut.
func Skip ¶
Skip returns an iterator that skips the first skip element in the sequence. If skip is a negative number, it returns an iterator that adds skip's absolute value number of zero values to the beginning of the sequence.
func Skip2 ¶
Skip2 returns an iterator that skips the first skip element in the sequence. If skip is a negative number, it returns an iterator that adds skip's absolute value number of zero values to the beginning of the sequence.
func Swap ¶
Swap converts an iter.Seq2[S, T] to an iter.Seq2[T, S]. The order of the sequence is not changed.
func Values ¶
Values converts iter.Seq2[K, V] to iter.Seq[V]. The order of the sequence is not changed.
func Zip ¶
Zip returns a composite iterator iter.Seq2[S, T] from two iterators iter.Seq[S] and iter.Seq[T]. Zip iterates over the smaller of the two sequences.
func ZipAll ¶
ZipAll returns a composite iterator iter.Seq2[S, T] from two iterators iter.Seq[S] and iter.Seq[T]. ZipAll iterates over the greater of the two sequences. Zero values are used for any missing elements in the sequence with fewer elements.
func ZipIndex ¶
ZipIndex converts an iter.Seq[T] to an iter.Seq2[int, T]. The int is the index of the element in the sequence. The order of the sequence is not changed.
func ZipLeft ¶
ZipLeft returns a composite iterator iter.Seq2[S, T] from two iterators iter.Seq[S] and iter.Seq[T]. ZipLeft iterates as many times as there are elements on the left. If there are fewer elements on the right than the left, zero values are used for the right.
Types ¶
This section is empty.