Documentation ¶
Index ¶
- Variables
- func Enumerate[TItem any](iter Iterator[TItem], pred EnumerateFunc[TItem])
- func Find[TItem any](iter Iterator[TItem], pred FindFunc[TItem]) (*TItem, error)
- func ForEach[TItem any](iter Iterator[TItem], pred ForEachFunc[TItem])
- func Reduce[TItem, TAggregate any](iter Iterator[TItem], reduce ReduceFunc[TItem, TAggregate], initial TAggregate) TAggregate
- type EnumerateFunc
- type FilterFunc
- type FindFunc
- type FlatMapFunc
- type ForEachFunc
- type IntoIterator
- type Iterator
- func Concat[TItem any](first, second Iterator[TItem]) Iterator[TItem]
- func Empty[TItem any]() Iterator[TItem]
- func Filter[TItem any](iter Iterator[TItem], pred FilterFunc[TItem]) Iterator[TItem]
- func FlatMap[TInput, TOutput any](iter Iterator[TInput], pred FlatMapFunc[TInput, TOutput]) Iterator[TOutput]
- func From[TItem any](into IntoIterator[TItem]) Iterator[TItem]
- func Map[TInput any, TOutput any](iter Iterator[TInput], pred MapFunc[TInput, TOutput]) Iterator[TOutput]
- func Range(start, end int) Iterator[int]
- func Take[TItem any](iter Iterator[TItem], n int) Iterator[TItem]
- type MapFunc
- type ReduceFunc
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
EnumerateFunc represents the predicate function passed to Enumerate
type FilterFunc ¶
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 ¶
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 ¶
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 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
type ReduceFunc ¶
type ReduceFunc[TItem, TAggregate any] func(TAggregate, TItem) TAggregate
ReduceFunc represents the predicate function passed to Reduce