iterutil

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enumerate added in v0.25.2

func Enumerate[E any](seq iter.Seq[E]) iter.Seq2[int, E]

Enumerate takes an iter.Seq and returns an iter.Seq2 where the first value is an int counter.

func Keys added in v0.25.2

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

Keys takes an iter.Seq2 and returns an iter.Seq that iterates over the first value in each pair of values.

func Map

func Map(err error) error

Map the nil if it is StopIteration, or keep the error otherwise

func MinFunc added in v0.25.2

func MinFunc[E any](seq iter.Seq[E], cmp func(E, E) int) E

MinFunc returns the minimum element in seq, using cmp to compare elements. If seq has no values, the zero value is returned.

func StopIteration

func StopIteration() error

StopIteration returns a sentinel error that indicates stopping the iteration.

This error should not be propagated further, i.e., if a closure returns this error, the loop should break returning nil error. For example:

f := func(i int) error {
	if i == 10 {
		return iterutil.StopIteration()
	}
	return nil
}

for i := range slice {
	if err := f(i); err != nil {
		return iterutil.Map(err)
	}
	// continue when nil error
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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