itz

package module
v0.0.0-...-a4ba21f Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Package itz implements additional utilities for Go iterators.

This library seeks to be aligned with patterns and naming used in the standard library such as the signatures in the `slices` package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append[T any](it iter.Seq[T], x T) iter.Seq[T]

Append extends the provided iterator with a single value.

func Chunk

func Chunk[T any](it iter.Seq[T], n int) iter.Seq[[]T]

Chunk is the equivalant of slices.Chunk, but for iterators.

func Chunk2

func Chunk2[T, V any](it iter.Seq2[T, V], n int) iter.Seq[[]Tuple[T, V]]

Chunk2 is the equivalant of Chunk, but for iter.Seq2.

func Concat

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

Concat composes iterators together in the provided order.

This is similar to Python's `itertools.chain(*iterables)`.

func Concat2

func Concat2[T, V any](seqs ...iter.Seq2[T, V]) iter.Seq2[T, V]

Concat2 composes arity-2 iterators together in the provided order.

func Filter

func Filter[T any](it iter.Seq[T], pred func(T) bool) iter.Seq[T]

Filter returns an iterator yielding all elements that the predicate returns truthy for.

func FlatMap

func FlatMap[T, R any](it iter.Seq[iter.Seq[T]], fn func(T) R) iter.Seq[R]

FlatMap flattens a nested iterator and applies a transformation function.

Friendly reminder: Go is not a functional programming language ;)

func Flatten

func Flatten[T any](it iter.Seq[iter.Seq[T]]) iter.Seq[T]

Flatten collapses a nested iterator.

func Map

func Map[T, R any](it iter.Seq[T], fn func(T) R) iter.Seq[R]

Map creates a new iterator with each element transformed by the provided function.

func MapE

func MapE[T, R any](it iter.Seq[T], fn func(T) (R, error)) iter.Seq2[R, error]

MapE creates a new iterator with each element transformed by the provided, falable function.

func MapOption

func MapOption[T, R any](it iter.Seq2[T, error], fn func(T) R) iter.Seq2[R, error]

MapOption iterates over a fallable iterator, stopping if an error is returned, but otherwise applies the transformation to each element.

func Pop

func Pop[T any](it iter.Seq[T]) (fst T, ok bool)

Pop returns the first element of an iterator.

func Take

func Take[T any](it iter.Seq[T], n int) iter.Seq[T]

Take returns the first n elements of an iterator.

Types

type Tuple

type Tuple[T, V any] struct {
	F0 T
	F1 V
}

Tuple represents a generic collection of two differently-typed items.

Jump to

Keyboard shortcuts

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