iterators

package
v0.0.0-...-7b96089 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStopIteration = errors.New("stop iteration")

Functions

func AsBufferedChannel

func AsBufferedChannel[IT Iterator[T], T any](iter IT, size int) <-chan T

func AsChannel

func AsChannel[IT Iterator[T], T any](iter IT) <-chan T

func Count

func Count[IT Iterator[T], T any](iter IT) int

func Fold

func Fold[IT Iterator[T], T any, U any](iter IT, initial U, fn func(U, T) U) U

func ForEach

func ForEach[IT Iterator[T], T any](iter IT, fn func(T))

func ForEachContext

func ForEachContext[IT Iterator[T], T any](ctx context.Context, iter IT, fn func(context.Context, T))

func PumpToChannel

func PumpToChannel[IT Iterator[T], T any](ctx context.Context, iter IT, ch chan<- T)

func Reduce

func Reduce[IT Iterator[T], T any, U any](iter IT, reducer func(Iterator[T]) U) U

func ToMap

func ToMap[IT Iterator[KeyValue[K, V]], K comparable, V any](iter IT) map[K]V

func ToSlice

func ToSlice[T any](iter Iterator[T]) []T

func ToSliceWithCapacity

func ToSliceWithCapacity[IT Iterator[T], T any](iter IT, capacity int) []T

Types

type Comparator

type Comparator[T any] func(T, T) int

type Iterable

type Iterable[T any] interface {
	Iterator() Iterator[T]
}

type Iterator

type Iterator[T any] interface {
	Next() bool
	Value() T
}

func Buffer

func Buffer[T any](iter Iterator[T], size int) Iterator[Iterator[T]]

func Buffered

func Buffered[T any](iter Iterator[T], size int) Iterator[T]

func Cancellable

func Cancellable[T any](ctx context.Context, iter Iterator[T]) Iterator[T]

func Concat

func Concat[IT Iterator[T], T any](iterators ...IT) Iterator[T]

func Filter

func Filter[IT Iterator[T], T any](iter IT, fn func(T) bool) Iterator[T]

func FilterIsInstance

func FilterIsInstance[T, U any](iter Iterator[T]) Iterator[U]

func FlatMap

func FlatMap[IT Iterator[T], T, U any](iter IT, fn func(T) Iterator[U]) Iterator[U]

func FromChannel

func FromChannel[T any](ch <-chan T) Iterator[T]

func FromMap

func FromMap[K comparable, V any](m map[K]V) Iterator[KeyValue[K, V]]

func FromSlice

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

func Map

func Map[IT Iterator[T], T, U any](iter IT, fn func(T) U) Iterator[U]

func NewIterator

func NewIterator[T any](fn func() (T, bool)) Iterator[T]

func OnEach

func OnEach[T any](iter Iterator[T], fn func(T)) Iterator[T]

func Safe

func Safe[IT Iterator[T], T any](iter IT) Iterator[Result[T]]

func Scan

func Scan[IT Iterator[T], T any, U any](iter IT, initial U, fn func(U, T) U) Iterator[U]

func SortWith

func SortWith[T any](src Iterator[T], comparator Comparator[T]) Iterator[T]

type KeyValue

type KeyValue[K comparable, V any] struct {
	K K
	V V
}

type ListIterator

type ListIterator[T any] interface {
	Iterator[T]

	Index() int
	Previous() bool
}

type MutableListIterator

type MutableListIterator[T any] interface {
	ListIterator[T]

	InsertBefore(v T)
	InsertAfter(v T)
	Set(v T)
	Remove()
}

type Reducer

type Reducer[T any, U any] interface {
	Reduce(Iterator[T]) U
}

type Result

type Result[T any] struct {
	Value T
	Err   error
}

Jump to

Keyboard shortcuts

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