Documentation ¶
Index ¶
- func Chain[T any, FI Iterator[T], SI Iterator[T]](first FI, second SI) *chainIterator[T, FI, SI, struct{}]
- func ChainWithMap[T any, FI Iterator[T], SI Iterator[T], MAP any](first FI, second SI) *chainIterator[T, FI, SI, MAP]
- func Chunk[T any, I Iterator[T]](iterator I, size int) chunker[T, I, struct{}]
- func ChunkWithMap[T any, I Iterator[T], MAP any](iterator I, size int) chunker[T, I, MAP]
- func Filter[T any, I Iterator[T]](iterator I, fn FilterFn[T]) *filterIterator[T, I, struct{}]
- func FilterWithMap[T any, I Iterator[T], MAP any](iterator I, fn FilterFn[T]) *filterIterator[T, I, MAP]
- func Map[T any, I Iterator[T], MAP any](iterator I, fn MapFn[T, MAP]) mapper[T, I, MAP]
- func Peekable[T any, I Iterator[T]](iterator I) *peekableIterator[T, I]
- func StepBy[T any, I Iterator[T]](iterator I, step int) *stepByIterator[T, I, struct{}]
- func StepByWithMap[T any, I Iterator[T], MAP any](iterator I, step int) *stepByIterator[T, I, MAP]
- func Take[T any, I Iterator[T]](iterator I, n int) *takeIterator[T, I, struct{}]
- func TakeWhile[T any, I Iterator[T]](iterator I, fn TakeWhileFn[T]) takeWhileIterator[T, I, struct{}]
- func TakeWhileWithMap[T any, I Iterator[T], MAP any](iterator Iterator[T], fn TakeWhileFn[T]) takeWhileIterator[T, I, MAP]
- func TakeWithMap[T any, I Iterator[T], MAP any](iterator I, n int) *takeIterator[T, I, MAP]
- func WrapMap[K comparable, V any](m map[K]V) mapWrapper[K, V, struct{}]
- func WrapMapWithMap[K comparable, V, MAP any](m map[K]V) mapWrapper[K, V, MAP]
- func WrapSlice[T any](slice []T) sliceWrapper[T, struct{}]
- func WrapSliceMap[T, MAP any](slice []T) sliceWrapper[T, MAP]
- type Entry
- type FilterFn
- type Iterate
- func (i Iterate[T, I, MAP]) All(fn func(T) bool) (isAll bool)
- func (i Iterate[T, I, MAP]) AllParallel(fn func(T) bool) (isAll bool)
- func (i Iterate[T, I, MAP]) Any(fn func(T) bool) (isAny bool)
- func (i Iterate[T, I, MAP]) AnyParallel(fn func(T) bool) (isAny bool)
- func (i Iterate[T, I, MAP]) Chain(iterator Iterator[T]) Iterate[T, Iterator[T], MAP]
- func (i Iterate[T, I, MAP]) Chunk(size int) chunker[T, Iterator[T], MAP]
- func (i Iterate[T, I, MAP]) Collect() (results []T)
- func (i Iterate[T, I, MAP]) CollectIter() sliceWrapper[T, MAP]
- func (i Iterate[T, I, MAP]) Count() (j int)
- func (i Iterate[T, I, MAP]) CountParallel() int
- func (i Iterate[T, I, MAP]) Filter(fn FilterFn[T]) Iterate[T, Iterator[T], MAP]
- func (i Iterate[T, I, MAP]) Find(fn func(T) bool) (result optionext.Option[T])
- func (i Iterate[T, I, MAP]) ForEach(fn func(T))
- func (i Iterate[T, I, MAP]) ForEachParallel(fn func(T))
- func (i Iterate[T, I, MAP]) Map(fn MapFn[T, MAP]) mapper[T, Iterator[T], MAP]
- func (i Iterate[T, I, MAP]) Next() optionext.Option[T]
- func (i Iterate[T, I, MAP]) Partition(fn func(v T) bool) (left, right []T)
- func (i Iterate[T, I, MAP]) PartitionIter(fn func(v T) bool) (left, right sliceWrapper[T, struct{}])
- func (i Iterate[T, I, MAP]) Peekable() *peekableIterator[T, Iterator[T]]
- func (i Iterate[T, I, MAP]) Position(fn func(T) bool) optionext.Option[int]
- func (i Iterate[T, I, MAP]) Reduce(fn func(accum T, current T) T) optionext.Option[T]
- func (i Iterate[T, I, MAP]) StepBy(step int) Iterate[T, Iterator[T], MAP]
- func (i Iterate[T, I, MAP]) Take(n int) Iterate[T, Iterator[T], MAP]
- func (i Iterate[T, I, MAP]) TakeWhile(fn TakeWhileFn[T]) Iterate[T, Iterator[T], MAP]
- type Iterator
- type MapFn
- type PeekableIterator
- type TakeWhileFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chain ¶
func Chain[T any, FI Iterator[T], SI Iterator[T]](first FI, second SI) *chainIterator[T, FI, SI, struct{}]
Chain creates a new `chainIterator[T]` for use.
func ChainWithMap ¶
func ChainWithMap[T any, FI Iterator[T], SI Iterator[T], MAP any](first FI, second SI) *chainIterator[T, FI, SI, MAP]
ChainWithMap creates a new `chainIterator[T]` for use and parameter to specify a Map type for the `Iterate.Map` helper function.
func Chunk ¶
Chunk creates a new `chunker` for use.
The default Map type is struct{}, see `ChunkWithMap` for details.
func ChunkWithMap ¶
ChunkWithMap creates a new `chunker` for use that accepts a Map type for use with `Iterate`.
func FilterWithMap ¶
func FilterWithMap[T any, I Iterator[T], MAP any](iterator I, fn FilterFn[T]) *filterIterator[T, I, MAP]
FilterWithMap creates a new `filterIterator` for use which also specifies a potential future `Map` operation.
func Peekable ¶
Peekable accepts and `Iterator[T]` and turns it into a Peekable iterator.
NOTE: Peekable iterators are commonly the LAST in a chain of iterators.
func StepByWithMap ¶
StepByWithMap returns a `stepByIterator[T]` for use and can specify a future `Map` type conversion.
func TakeWhile ¶
func TakeWhile[T any, I Iterator[T]](iterator I, fn TakeWhileFn[T]) takeWhileIterator[T, I, struct{}]
TakeWhile creates a new `takeWhileIterator[T,I]` for use.
func TakeWhileWithMap ¶
func TakeWhileWithMap[T any, I Iterator[T], MAP any](iterator Iterator[T], fn TakeWhileFn[T]) takeWhileIterator[T, I, MAP]
TakeWhileWithMap creates a new `takeWhileIterator[T,I]` for use and can specify a future `Map` type conversion.
func TakeWithMap ¶
TakeWithMap creates a new `takeIterator[T]` for use and can specify a future `Map` type conversion.
func WrapMap ¶
func WrapMap[K comparable, V any](m map[K]V) mapWrapper[K, V, struct{}]
WrapMap creates a new iterator for transformation of types.
func WrapMapWithMap ¶
func WrapMapWithMap[K comparable, V, MAP any](m map[K]V) mapWrapper[K, V, MAP]
WrapMapWithMap creates a new `mapWrapper` for use which also specifies a potential future `Map` operation.
func WrapSlice ¶
func WrapSlice[T any](slice []T) sliceWrapper[T, struct{}]
WrapSlice accepts and turns a sliceWrapper into an iterator.
The default the Map type to struct{} when none is required. See WrapSliceMap if one is needed.
func WrapSliceMap ¶
func WrapSliceMap[T, MAP any](slice []T) sliceWrapper[T, MAP]
WrapSliceMap accepts and turns a sliceWrapper into an iterator with a map type specified for IterPar() to allow the Map helper function.
Types ¶
type Entry ¶
type Entry[K comparable, V any] struct { Key K Value V }
Entry represents a single Map entry.
type Iterate ¶
Iterate is an iterator with attached helper functions
func Iter ¶
Iter creates a new iterator with helper functions.
It defaults the Map() function to struct{}. Use IterMap() if you wish to specify a type.
func IterMap ¶
IterMap creates a new iterator with helper functions.
It accepts a map type `MAP` to allow for usage of the `Map` and `CollectMap` helper function inline. You must use the Map() function standalone otherwise.
func (Iterate[T, I, MAP]) All ¶
All returns true if all element matches the function return, false otherwise.
func (Iterate[T, I, MAP]) AllParallel ¶
AllParallel returns true if all element matches the function return, false otherwise.
This will run in parallel. It is recommended to only use this when the overhead of running n parallel is less than the work needing to be done.
func (Iterate[T, I, MAP]) Any ¶
Any returns true if any element matches the function return, false otherwise.
func (Iterate[T, I, MAP]) AnyParallel ¶
AnyParallel returns true if any element matches the function return, false otherwise.
This will run in parallel. It is recommended to only use this when the overhead of running n parallel is less than the work needing to be done.
func (Iterate[T, I, MAP]) Chunk ¶
Chunk returns a `*Iterate[T, V]` the returns an []T of the specified size
The last slice is not guaranteed to be the exact chunk size when iterator finishes the remainder is returned.
func (Iterate[T, I, MAP]) Collect ¶
func (i Iterate[T, I, MAP]) Collect() (results []T)
Collect transforms an iterator into a sliceWrapper.
This will run in parallel is using a parallel iterator.
func (Iterate[T, I, MAP]) CollectIter ¶
func (i Iterate[T, I, MAP]) CollectIter() sliceWrapper[T, MAP]
CollectIter transforms an iterator into a sliceWrapper and returns a *sliceWrapper in order to run additional functions inline such as Sort().
eg. .Filter(...).CollectIter().Sort(...).WrapSlice()
This will run in parallel is using a parallel iterator.
func (Iterate[T, I, MAP]) Count ¶
Count consumes the iterator and returns count if iterations.
This will run in parallel is using a parallel iterator.
func (Iterate[T, I, MAP]) CountParallel ¶
CountParallel consumes the iterator concurrently and returns count if iterations.
func (Iterate[T, I, MAP]) Find ¶
Find searches for the next element of an iterator that satisfies the function.
func (Iterate[T, I, MAP]) ForEach ¶
func (i Iterate[T, I, MAP]) ForEach(fn func(T))
ForEach runs the provided function for each element until completion.
This will run in parallel is using a parallel iterator.
func (Iterate[T, I, MAP]) ForEachParallel ¶
func (i Iterate[T, I, MAP]) ForEachParallel(fn func(T))
ForEachParallel runs the provided function for each element in parallel until completion.
The function must maintain its own thread safety.
func (Iterate[T, I, MAP]) Map ¶
Map accepts a `FilterFn[T]` to filter items.
NOTE: This is made possible by passing the one-time possible MAP type around. This is unfortunate but the only way it can be supported due to the limitations of the Go Compiler.
Since it's a likely function to be used inline it has been done this way for convenience.
func (Iterate[T, I, MAP]) Partition ¶
Partition creates two collections from supplied function, all elements returning true will be in one result and all that were returned false in the other.
func (Iterate[T, I, MAP]) PartitionIter ¶
func (i Iterate[T, I, MAP]) PartitionIter(fn func(v T) bool) (left, right sliceWrapper[T, struct{}])
PartitionIter creates two iterable collections from supplied function, all elements returning true will be in one result and all that were returned false in the other.
func (Iterate[T, I, MAP]) Peekable ¶
Peekable returns a `PeekableIterator[T]` that wraps the current iterator.
NOTE: Peekable iterators are commonly the LAST in a chain of iterators.
func (Iterate[T, I, MAP]) Position ¶
Position searches for an element in an iterator, returning its index.
func (Iterate[T, I, MAP]) Reduce ¶
Reduce reduces the elements to a single one, by repeatedly applying a reducing function.
func (Iterate[T, I, MAP]) StepBy ¶
StepBy returns a `Iterate[T, V]` starting at the same point, but stepping by the given amount at each iteration.
The first element is always returned before the stepping begins.
type Iterator ¶
type Iterator[T any] interface { // Next advances the iterator and returns the next value. // // Returns an Option with value of None when iteration has finished. Next() optionext.Option[T] }
Iterator is an interface representing something that iterates using the Next method.
type MapFn ¶
type MapFn[T, MAP any] func(v T) MAP
MapFn represents the mapWrapper transformation function.
type PeekableIterator ¶
type PeekableIterator[T any] interface { Iterator[T] // Peek returns the `Next` element from the `Iterator` without advancing it. Peek() optionext.Option[T] }
PeekableIterator is an interface representing something that iterates using the Next method and ability to `Peek` the next element value without advancing the `Iterator`.
type TakeWhileFn ¶
TakeWhileFn represents the `takeWhileIterator[T]` function.