iterators

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: Apache-2.0 Imports: 4 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEach

func ForEach[V any](it Iterator[*V], consume ConsumeFunc[*V]) error

ForEach executes the given ConsumeFunc for each element of the Iterator

func GetFirst

func GetFirst[T any](vs Iterator[T]) (T, error)

GetFirst returns the first element of an Iterator, when there may be more than one

func GetUnique

func GetUnique[T any](vs Iterator[T]) (T, error)

GetUnique returns the unique element of an Iterator, when there is supposed to be only one

func ReadAllPointers

func ReadAllPointers[T any](it Iterator[*T]) ([]*T, error)

ReadAllPointers reads all pointer elements of an Iterator and returns them

func ReadAllValues

func ReadAllValues[T any](it Iterator[*T]) ([]T, error)

ReadAllValues reads all pointer elements of an Iterator and returns the values No nil elements are expected!

func ReadFirst

func ReadFirst[T any](it Iterator[*T], limit int) ([]T, error)

ReadFirst reads the first {{limit}} elements of the input Iterator

func Reduce

func Reduce[V any, S any](it Iterator[*V], reducer Reducer[*V, S]) (S, error)

Reduce reduces the elements of an iterator into an aggregated structure

func ReduceValue

func ReduceValue[V any, S any](it Iterator[*V], result S, reduce ReduceFunc[*V, S]) (S, error)

Types

type ConsumeFunc

type ConsumeFunc[V any] func(V) error

type Iterator

type Iterator[V any] interface {

	// Close releases resources occupied by the iterator
	Close()
	// contains filtered or unexported methods
}

func Batch

func Batch[V any](it Iterator[*V], batchSize uint32) Iterator[*[]*V]

Batch lazily batches the elements of an iterator into groups of {{batchSize}} sized batches Each element of the output Iterator will now be a batch, i.e. a slice of the initial elements

func Copy

func Copy[T any](it Iterator[*T]) (Iterator[*T], error)

Copy returns a copy of the input Iterator

func Empty

func Empty[K any]() Iterator[K]

Empty returns an empty Iterator

func Filter

func Filter[A any](iterator Iterator[*A], filter Predicate[*A]) Iterator[*A]

Filter lazily filters an iterator

func Map

func Map[A any, B any](iterator Iterator[A], transformer Transformer[A, B]) Iterator[B]

Map lazily maps an iterator to another

type PermutatableIterator

type PermutatableIterator[V any] interface {
	Iterator[V]
	NewPermutation() Iterator[V]
}

func From

func From[T any](items ...T) PermutatableIterator[T]

From creates an Iterator containing the passed elements

func Permutate

func Permutate[T any](it Iterator[*T]) (PermutatableIterator[*T], error)

Permutate creates a new Iterator that contains the elements of the input Iterator permutated

func Slice

func Slice[T any](items []T) PermutatableIterator[T]

Slice creates an iterator from the elements of the passed slice

type Predicate

type Predicate[V any] func(V) bool

func DuplicatesBy

func DuplicatesBy[V any, I comparable](prop func(V) I) Predicate[V]

DuplicatesBy is used for filtering duplicate elements by a comparable property

type ReduceFunc

type ReduceFunc[V any, S any] func(S, V) (S, error)

type Reducer

type Reducer[V any, S any] interface {
	Produce() S
	Reduce(S, V) (S, error)
}

func NewReducer

func NewReducer[V any, S any](initial S, merge ReduceFunc[V, S]) Reducer[V, S]

NewReducer creates a generic reducer

func ToFlattened

func ToFlattened[V any]() Reducer[*[]V, []V]

ToFlattened creates a reducer that collects the slice elements of an Iterator into a flattened slice

func ToSet

func ToSet[V comparable]() Reducer[*V, sets.Set[V]]

ToSet creates a reducer that collects the comparable elements of an Iterator into a Set

type Transformer

type Transformer[A any, B any] func(A) (B, error)

Jump to

Keyboard shortcuts

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