iterator

package
v0.0.0-...-81dff9f Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("item not found")

Functions

func Enumerate

func Enumerate[TItem any](iter Iterator[TItem], pred EnumerateFunc[TItem])

Enumerate provides ForEach functionality, but also passes item index to the predicate function

func Find

func Find[TItem any](iter Iterator[TItem], pred FindFunc[TItem]) (*TItem, error)

Find returns the first item in the given iterator where the predicate function returns true

func ForEach

func ForEach[TItem any](
	iter Iterator[TItem],
	pred ForEachFunc[TItem],
)

ForEach iterates over all items in the given iterator, passing each to the given predicate function

func Reduce

func Reduce[TItem, TAggregate any](
	iter Iterator[TItem],
	reduce ReduceFunc[TItem, TAggregate],
	initial TAggregate,
) TAggregate

Reduce applies the given predicate function to all items in the given iterator, aggregating the result that is eventually returned.

Types

type EnumerateFunc

type EnumerateFunc[TItem any] func(TItem, int)

EnumerateFunc represents the predicate function passed to Enumerate

type FilterFunc

type FilterFunc[TItem any] func(TItem) bool

FilterFunc represents the predicate function passed to Filter. Items that would result in this function returning true will be included in the resulting iterator

type FindFunc

type FindFunc[TItem any] func(TItem) bool

FindFunc represents the predicate function passed to Find. The first item that would result in this function returning true will be the returned from Find

type FlatMapFunc

type FlatMapFunc[TInput, TOutput any] MapFunc[TInput, IntoIterator[TOutput]]

FlatMapFunc represents the predicate function passed to FlatMap

type ForEachFunc

type ForEachFunc[TItem any] func(TItem)

ForEachFunc represents the predicate function passed to ForEach

type IntoIterator

type IntoIterator[TItem any] interface {
	Iter() Iterator[TItem]
}

IntoIterator provides the Iter method used to obtain an iterator over a collection

type Iterator

type Iterator[TItem any] interface {
	// Next returns the next item in the
	// iterator, otherwise nil
	Next() *TItem
}

Iterator provides the required method Next for use in other iterator functions

func Concat

func Concat[TItem any](first, second Iterator[TItem]) Iterator[TItem]

Concat concatenates the second iterator onto the end of the first iterator

func Empty

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

Empty returns an empty iterator

func Filter

func Filter[TItem any](
	iter Iterator[TItem],
	pred FilterFunc[TItem],
) Iterator[TItem]

Filter returns an iterator over the items in the given iterator where the given predicate function returns true

func FlatMap

func FlatMap[TInput, TOutput any](
	iter Iterator[TInput],
	pred FlatMapFunc[TInput, TOutput],
) Iterator[TOutput]

FlatMap returns an iterator over the transformed and flattened items from the given iterator, according to the predicate function

func From

func From[TItem any](into IntoIterator[TItem]) Iterator[TItem]

From returns an iterator from an IntoIterator

func Map

func Map[TInput any, TOutput any](
	iter Iterator[TInput],
	pred MapFunc[TInput, TOutput],
) Iterator[TOutput]

Map returns an iterator of the transformed items of the given iterator, according to the given predicate function

func Range

func Range(start, end int) Iterator[int]

func Take

func Take[TItem any](iter Iterator[TItem], n int) Iterator[TItem]

Take returns an iterator over a subset of the given iterator, taking the first n items

type MapFunc

type MapFunc[TInput any, TOutput any] func(TInput) TOutput

MapFunc represents the predicate function passed to Map

type ReduceFunc

type ReduceFunc[TItem, TAggregate any] func(TAggregate, TItem) TAggregate

ReduceFunc represents the predicate function passed to Reduce

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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