iter

package
v0.0.0-...-4064505 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Overview

Utilities for iterator types.

This package should be deprecated in favor of std or x/exp/iter when they are generally available without build flag constraints.

Index

Constants

View Source
const (
	Continue = Flow(true)
	Break    = Flow(false)
)

Variables

This section is empty.

Functions

func All

func All(iter Iter[bool]) bool

func Any

func Any(iter Iter[bool]) bool

func CollectMap

func CollectMap[K comparable, V any](iter Iter[Pair[K, V]]) map[K]V

func CollectSet

func CollectSet[T comparable](iter Iter[T]) sets.Set[T]

func FirstSome

func FirstSome[T any](iter Iter[optional.Optional[T]]) optional.Optional[T]

func Histogram

func Histogram[T comparable](iter Iter[T]) map[T]int

func Sum

func Sum[T constraints.Integer](iter Iter[T]) T

Types

type Flow

type Flow bool

`Continue` or `Break`.

func ContinueIf

func ContinueIf(condition bool) Flow

func (Flow) Break

func (flow Flow) Break() bool

func (Flow) Continue

func (flow Flow) Continue() bool

type Iter

type Iter[T any] func(yield Yield[T]) Flow

A pushing iterator that yields items of type `T`.

func Chain

func Chain[T any](iters ...Iter[T]) Iter[T]

func Deduplicate

func Deduplicate[T comparable](iter Iter[T]) Iter[T]

func Empty

func Empty[T any]() Iter[T]

func Enumerate

func Enumerate[T any](iter Iter[T]) Iter[Pair[uint64, T]]

func FlatMap

func FlatMap[T any, U any](iter Iter[T], mapFn func(T) Iter[U]) Iter[U]

func FromMap

func FromMap[K comparable, V any](m map[K]V) Iter[Pair[K, V]]

func FromMap2

func FromMap2[K comparable, V1 any, V2 any](
	m1 map[K]V1,
	m2 map[K]V2,
) Iter[Pair[K, Pair[optional.Optional[V1], optional.Optional[V2]]]]

Iterate over the union of keys from two different maps.

func FromSet

func FromSet[T comparable](slice sets.Set[T]) Iter[T]

func FromSlice

func FromSlice[T any](slice []T) Iter[T]

func Map

func Map[T any, U any](iter Iter[T], mapFn func(T) U) Iter[U]

func MapKeys

func MapKeys[K comparable, V any](map_ map[K]V) Iter[K]

func MapKvs

func MapKvs[K comparable, V any](map_ map[K]V) Iter[Pair[K, V]]

func MapValues

func MapValues[K comparable, V any](map_ map[K]V) Iter[V]

func Range

func Range[T constraints.Integer](start, end T) Iter[T]

func Repeat

func Repeat[T any](value T, count uint64) Iter[T]

func Zip

func Zip[Left, Right any](
	leftSlice []Left,
	rightSlice []Right,
) Iter[Pair[optional.Optional[Left], optional.Optional[Right]]]

Iterate over two slices concurrently, yielding `None` on up to one side if a slice is shorter.

func (Iter[T]) CollectSlice

func (iter Iter[T]) CollectSlice() []T

func (Iter[T]) Defer

func (iter Iter[T]) Defer(finalizer func()) Iter[T]

func (Iter[T]) Filter

func (iter Iter[T]) Filter(filterFn func(T) bool) Iter[T]

func (Iter[T]) MustBeAffine

func (iter Iter[T]) MustBeAffine(message string) Iter[T]

Ensures that the iterator can only be used once. Attempt to reuse would result in panic.

func (Iter[T]) TryForEach

func (iter Iter[T]) TryForEach(eachFn func(T) error) error

type Pair

type Pair[Left any, Right any] struct {
	Left  Left
	Right Right
}

func NewPair

func NewPair[Left any, Right any](left Left, right Right) Pair[Left, Right]

type Yield

type Yield[T any] func(T) Flow

Receives items of type `T` and determines whether the iterator should be interrupted.

Jump to

Keyboard shortcuts

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