iterutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package iterutil provides generic iterator utility functions for Go's iter.Seq type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any[V any](
	f func(V) bool,
	seq iter.Seq[V],
) bool

Any returns true if at least one of the elements in seq matches the predicate f, false otherwise.

func AnyWith

func AnyWith[V any](f func(V) bool) func(iter.Seq[V]) bool

AnyWith returns a curried version of Any that takes a predicate function and returns a function that checks if any element matches.

func Concat

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

Concat returns an iterator over the concatenation of the sequences.

func Contains

func Contains[V comparable](
	element V,
	seq iter.Seq[V],
) bool

Contains returns true if element is present in seq, false otherwise.

func ContainsElement

func ContainsElement[V comparable](element V) func(iter.Seq[V]) bool

ContainsElement returns a curried version of Contains that takes an element and returns a function that checks if the element is present in a sequence.

func Delete

func Delete[V any](
	f func(V) bool,
	seq iter.Seq[V],
) iter.Seq[V]

Delete returns an iterator over seq that excludes the values v for which f(v) is true.

func DeleteWith

func DeleteWith[V any](f func(V) bool) func(iter.Seq[V]) iter.Seq[V]

DeleteWith returns a curried version of Delete that takes a predicate function and returns a function that removes matching elements from a sequence.

func Equal

func Equal[V comparable](xit, yit iter.Seq[V]) bool

Equal reports whether the two sequences are equal.

func Filter

func Filter[V any](
	f func(V) bool,
	seq iter.Seq[V],
) iter.Seq[V]

Filter returns an iterator over seq that only includes the values v for which f(v) is true.

func FilterWith

func FilterWith[V any](f func(V) bool) func(iter.Seq[V]) iter.Seq[V]

FilterWith returns a curried version of Filter that takes a predicate function and returns a function that filters a sequence.

func Find

func Find[V comparable](
	element V,
	seq iter.Seq[V],
) bool

Find is an alias for Contains.

func Map

func Map[In, Out any](
	f func(In) Out,
	seq iter.Seq[In],
) iter.Seq[Out]

Map returns an iterator over f applied to seq.

func MapWith

func MapWith[In, Out any](f func(In) Out) func(iter.Seq[In]) iter.Seq[Out]

MapWith returns a curried version of Map that takes a transformation function and returns a function that applies it to a sequence.

func Reduce

func Reduce[Sum, V any](
	f func(Sum, V) Sum,
	sum Sum,
	seq iter.Seq[V],
) Sum

Reduce combines the values in seq using f. For each value v in seq, it updates sum = f(sum, v) and then returns the final sum. For example, if iterating over seq yields v1, v2, v3, Reduce returns f(f(f(sum, v1), v2), v3).

func ReduceWith

func ReduceWith[Sum, V any](f func(Sum, V) Sum, sum Sum) func(iter.Seq[V]) Sum

ReduceWith returns a curried version of Reduce that takes a reducer function and initial value, returning a function that reduces a sequence.

func Zip

func Zip[V1, V2 any](
	xit iter.Seq[V1],
	yit iter.Seq[V2],
) iter.Seq[Zipped[V1, V2]]

Zip returns an iterator that iterates x and y in parallel, yielding Zipped values of successive elements of x and y. If one sequence ends before the other, the iteration continues with Zipped values in which either Ok1 or Ok2 is false, depending on which sequence ended first.

Types

type Zipped

type Zipped[V1, V2 any] struct {
	V1  V1
	Ok1 bool // whether V1 is present (if not, it will be zero)
	V2  V2
	Ok2 bool // whether V2 is present (if not, it will be zero)
}

A Zipped is a pair of zipped values, one of which may be missing, drawn from two different sequences.

Jump to

Keyboard shortcuts

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