transform

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package transform provides functions transforming iterators.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Concat

func Concat[T any](iterators ...iter.Seq[T]) iter.Seq[T]

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

func Concat2[S, T any](iterators ...iter.Seq2[S, T]) iter.Seq2[S, T]

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 Keys

func Keys[K, V any](iterator iter.Seq2[K, V]) iter.Seq[K]

Keys converts iter.Seq2[K, V] to iter.Seq[K]. The order of the sequence is not changed.

func Map

func Map[S, T any](iterator iter.Seq[S], f func(S) T) iter.Seq[T]

Map transforms iter.Seq[S] to iter.Seq[T] using f, which transforms S to T.

func Map2

func Map2[S, T, U, V any](iterator iter.Seq2[S, T], f func(S, T) (U, V)) iter.Seq2[U, V]

Map2 transforms iter.Seq2[S, T] to iter.Seq2[U, V] using f, which transforms S and T to U and V.

func MapIn

func MapIn[S, T, U any](iterator iter.Seq2[S, T], f func(S, T) U) iter.Seq[U]

MapIn transforms iter.Seq2[S, T] to iter.Seq[U] using f, which transforms S and T to U.

func MapOut

func MapOut[S, T, U any](iterator iter.Seq[S], f func(S) (T, U)) iter.Seq2[T, U]

MapOut transforms iter.Seq[S] to iter.Seq2[T, U] using f, which transforms S to T and U.

func Resize

func Resize[T any](iterator iter.Seq[T], size int) iter.Seq[T]

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

func Resize2[S, T any](iterator iter.Seq2[S, T], size int) iter.Seq2[S, T]

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

func Select[T any](iterator iter.Seq[T], f func(T) bool) iter.Seq[T]

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

func Select2[K, V any](iterator iter.Seq2[K, V], f func(K, V) bool) iter.Seq2[K, V]

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

func SelectMap[S, T any](iterator iter.Seq[S], f func(S) (T, bool)) iter.Seq[T]

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

func SelectMapIn[S, T, U any](iterator iter.Seq2[S, T], f func(S, T) (U, bool)) iter.Seq[U]

SelectMapIn provides functionality that combines the function of Select2 and MapIn.

func SelectMapOut added in v1.2.0

func SelectMapOut[S, T, U any](iterator iter.Seq[S], f func(S) (T, U, bool)) iter.Seq2[T, U]

SelectMapOut provides functionality that combines the function of Select and MapOut.

func Skip

func Skip[T any](iterator iter.Seq[T], skip int) iter.Seq[T]

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

func Skip2[S, T any](iterator iter.Seq2[S, T], skip int) iter.Seq2[S, T]

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

func Swap[S, T any](iterator iter.Seq2[S, T]) iter.Seq2[T, S]

Swap converts an iter.Seq2[S, T] to an iter.Seq2[T, S]. The order of the sequence is not changed.

func Values

func Values[K, V any](iterator iter.Seq2[K, V]) iter.Seq[V]

Values converts iter.Seq2[K, V] to iter.Seq[V]. The order of the sequence is not changed.

func Zip

func Zip[S, T any](lhs iter.Seq[S], rhs iter.Seq[T]) iter.Seq2[S, T]

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

func ZipAll[S, T any](lhs iter.Seq[S], rhs iter.Seq[T]) iter.Seq2[S, T]

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

func ZipIndex[T any](iterator iter.Seq[T]) iter.Seq2[int, T]

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

func ZipLeft[S, T any](lhs iter.Seq[S], rhs iter.Seq[T]) iter.Seq2[S, T]

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.

func ZipRight

func ZipRight[S, T any](lhs iter.Seq[S], rhs iter.Seq[T]) iter.Seq2[S, T]

ZipRight returns a composite iterator iter.Seq2[S, T] from two iterators iter.Seq[S] and iter.Seq[T]. ZipRight iterates as many times as there are elements on the right. If there are fewer elements on the left than the right, zero values are used for the left.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL