Documentation ¶
Overview ¶
Package loop provides helpers for loop operation and iterator implementations
Index ¶
- Variables
- func Append[T any, TS ~[]T](next func() (T, bool), out TS) TS
- func Contains[T comparable](next func() (T, bool), example T) bool
- func Conv[From, To any](next func() (From, bool), converter func(From) (To, error)) loop.ConvertIter[From, To]
- func ConvAndReduce[From, To any](next func() (From, bool), converter func(From) (To, error), ...) (out To, err error)
- func ConvCheck[From, To any](next func() (From, bool), converter func(from From) (To, bool, error)) loop.ConvertCheckIter[From, To]
- func ConvertAndReduce[From, To any](next func() (From, bool), converter func(From) To, merger func(To, To) To) (out To)
- func Filt[T any](next func() (T, bool), filter func(T) (bool, error)) loop.FiltIter[T]
- func First[T any](next func() (T, bool), predicate func(T) bool) (v T, ok bool)
- func FitAndConv[From, To any](next func() (From, bool), filter func(From) (bool, error), ...) loop.ConvertFitIter[From, To]
- func FitAndFlat[From, To any](next func() (From, bool), filter func(From) (bool, error), ...) loop.FlattenFitIter[From, To]
- func FitFlatFit[From, To any](next func() (From, bool), filterFrom func(From) (bool, error), ...) loop.FlattenFitIter[From, To]
- func Flat[From, To any](next func() (From, bool), flattener func(From) ([]To, error)) loop.FlatIter[From, To]
- func FlatAndFit[From, To any](next func() (From, bool, error), flattener func(From) ([]To, error), ...) loop.FlattenFitIter[From, To]
- func FlatKeys[T, K, V any](next func() (T, bool), keysExtractor func(T) ([]K, error), ...) *loop.MultipleKeyValuer[T, K, V]
- func FlatValues[T, K, V any](next func() (T, bool), keyExtractor func(T) (K, error), ...) *loop.MultipleKeyValuer[T, K, V]
- func For[T any](next func() (T, bool), walker func(T) error) error
- func ForEach[T any](next func() (T, bool), walker func(T))
- func ForEachFiltered[T any](next func() (T, bool), walker func(T), predicate func(T) bool)
- func Group[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V) map[K][]V
- func GroupByMultiple[T any, K comparable, V any](next func() (T, bool), keysExtractor func(T) []K, valsExtractor func(T) []V) map[K][]V
- func GroupByMultipleKeys[T any, K comparable, V any](next func() (T, bool), keysExtractor func(T) []K, valExtractor func(T) V) map[K][]V
- func GroupByMultipleValues[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) K, valsExtractor func(T) []V) map[K][]V
- func HasAny[T any](next func() (T, bool), predicate func(T) bool) bool
- func New[S, T any](source S, hasNext func(S) bool, getNext func(S) T) func() (T, bool)
- func Of[T any](elements ...T) func() (e T, ok bool)
- func OfIndexed[T any](len int, next func(int) T) func() (T, bool)
- func Range[T constraints.Integer](from T, toExclusive T) func() (T, bool)
- func RangeClosed[T constraints.Integer](from T, toInclusive T) func() (T, bool)
- func Reduce[T any](next func() (T, bool), merger func(T, T) T) (result T)
- func Slice[T any](next func() (T, bool)) []T
- func SliceCap[T any](next func() (T, bool), cap int) (out []T)
- func Sum[T c.Summable](next func() (T, bool)) T
- func ToMapResolv[T any, K comparable, V, VR any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V, ...) map[K]VR
- func Track[I, T any](next func() (I, T, bool), tracker func(I, T) error) error
- func TrackEach[I, T any](next func() (I, T, bool), tracker func(I, T))
- type ConvertCheckIter
- type ConvertFitIter
- func ConvertAndFilter[From, To any](next func() (From, bool), converter func(From) To, filter func(To) bool) ConvertFitIter[From, To]
- func FilterAndConvert[From, To any](next func() (From, bool), filter func(From) bool, converter func(From) To) ConvertFitIter[From, To]
- func FilterConvertFilter[From, To any](next func() (From, bool), filter func(From) bool, converter func(From) To, ...) ConvertFitIter[From, To]
- type ConvertIter
- type FitIter
- type FlatIter
- type FlattenFitIter
- func FilterAndFlatt[From, To any](next func() (From, bool), filter func(From) bool, flattener func(From) []To) FlattenFitIter[From, To]
- func FilterFlattFilter[From, To any](next func() (From, bool), filterFrom func(From) bool, ...) FlattenFitIter[From, To]
- func FlattAndFilter[From, To any](next func() (From, bool), flattener func(From) []To, filterTo func(To) bool) FlattenFitIter[From, To]
- type KeyValuer
- type Looper
- type MultipleKeyValuer
- func FlattKeys[T, K, V any](next func() (T, bool), keysExtractor func(T) []K, valExtractor func(T) V) *MultipleKeyValuer[T, K, V]
- func FlattValues[T, K, V any](next func() (T, bool), keyExtractor func(T) K, valsExtractor func(T) []V) *MultipleKeyValuer[T, K, V]
- func NewMultipleKeyValuer[T any, K, V any](next func() (T, bool), keysExtractor func(T) []K, valsExtractor func(T) []V) MultipleKeyValuer[T, K, V]
- func ToKVs[T, K, V any](next func() (T, bool), keysExtractor func(T) []K, valsExtractor func(T) []V) *MultipleKeyValuer[T, K, V]
Constants ¶
This section is empty.
Variables ¶
var ErrBreak = c.ErrBreak
ErrBreak is the 'break' statement of the For, Track methods
Functions ¶
func Append ¶
Append collects the elements retrieved by the 'next' function into the specified 'out' slice
func Contains ¶
func Contains[T comparable](next func() (T, bool), example T) bool
Contains finds the first element that equal to the example and returns true
func Conv ¶ added in v0.0.8
func Conv[From, To any](next func() (From, bool), converter func(From) (To, error)) loop.ConvertIter[From, To]
Conv instantiates an iterator that converts elements with a converter and returns them.
func ConvAndReduce ¶ added in v0.0.8
func ConvAndReduce[From, To any](next func() (From, bool), converter func(From) (To, error), merger func(To, To) To) (out To, err error)
ConvAndReduce converts each elements and merges them into one
func ConvCheck ¶ added in v0.0.8
func ConvCheck[From, To any](next func() (From, bool), converter func(from From) (To, bool, error)) loop.ConvertCheckIter[From, To]
ConvCheck is similar to ConvertFit, but it checks and transforms elements together
func ConvertAndReduce ¶ added in v0.0.8
func ConvertAndReduce[From, To any](next func() (From, bool), converter func(From) To, merger func(To, To) To) (out To)
ConvertAndReduce converts each elements and merges them into one
func Filt ¶ added in v0.0.8
Filt creates an iterator that checks elements by the 'filter' function and returns successful ones.
func First ¶
First returns the first element that satisfies the condition of the 'predicate' function
func FitAndConv ¶ added in v0.0.8
func FitAndConv[From, To any](next func() (From, bool), filter func(From) (bool, error), converter func(From) (To, error)) loop.ConvertFitIter[From, To]
FitAndConv returns a stream that filters source elements and converts them
func FitAndFlat ¶ added in v0.0.8
func FitAndFlat[From, To any](next func() (From, bool), filter func(From) (bool, error), flattener func(From) ([]To, error)) loop.FlattenFitIter[From, To]
FitAndFlat filters source elements and extracts slices of 'To' by the 'flattener' function
func FitFlatFit ¶ added in v0.0.8
func FitFlatFit[From, To any](next func() (From, bool), filterFrom func(From) (bool, error), flattener func(From) ([]To, error), filterTo func(To) (bool, error)) loop.FlattenFitIter[From, To]
FitFlatFit filters source elements, extracts slices of 'To' by the 'flattener' function and filters extracted elements
func Flat ¶ added in v0.0.8
func Flat[From, To any](next func() (From, bool), flattener func(From) ([]To, error)) loop.FlatIter[From, To]
Flat instantiates an iterator that extracts slices of 'To' by a flattener from elements of 'From' and flattens as one iterable collection of 'To' elements.
func FlatAndFit ¶ added in v0.0.8
func FlatAndFit[From, To any](next func() (From, bool, error), flattener func(From) ([]To, error), filterTo func(To) (bool, error)) loop.FlattenFitIter[From, To]
FlatAndFit extracts slices of 'To' by the 'flattener' function and filters extracted elements
func FlatKeys ¶ added in v0.0.8
func FlatKeys[T, K, V any](next func() (T, bool), keysExtractor func(T) ([]K, error), valExtractor func(T) (V, error)) *loop.MultipleKeyValuer[T, K, V]
FlatKeys transforms iterable elements to key/value iterator based on applying key, value extractor to the elements
func FlatValues ¶ added in v0.0.8
func FlatValues[T, K, V any](next func() (T, bool), keyExtractor func(T) (K, error), valsExtractor func(T) ([]V, error)) *loop.MultipleKeyValuer[T, K, V]
FlatValues transforms iterable elements to key/value iterator based on applying key, value extractor to the elements
func For ¶
For applies the 'walker' function for the elements retrieved by the 'next' function. Return the c.ErrBreak to stop
func ForEach ¶
ForEach applies the 'walker' function to the elements retrieved by the 'next' function
func ForEachFiltered ¶
ForEachFiltered applies the 'walker' function to the elements retrieved by the 'next' function that satisfy the 'predicate' function condition
func Group ¶
func Group[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V) map[K][]V
Group converts elements retrieved by the 'next' function into a map, extracting a key for each element applying the converter 'keyExtractor'. The keyExtractor converts an element to a key. The valExtractor converts an element to an value.
func GroupByMultiple ¶
func GroupByMultiple[T any, K comparable, V any](next func() (T, bool), keysExtractor func(T) []K, valsExtractor func(T) []V) map[K][]V
GroupByMultiple converts elements retrieved by the 'next' function into a map, extracting multiple keys, values per each element applying the 'keysExtractor' and 'valsExtractor' functions. The keysExtractor retrieves one or more keys per element. The valsExtractor retrieves one or more values per element.
func GroupByMultipleKeys ¶
func GroupByMultipleKeys[T any, K comparable, V any](next func() (T, bool), keysExtractor func(T) []K, valExtractor func(T) V) map[K][]V
GroupByMultipleKeys converts elements retrieved by the 'next' function into a map, extracting multiple keys, one value per each element applying the 'keysExtractor' and 'valExtractor' functions. The keysExtractor retrieves one or more keys per element. The valExtractor converts an element to a value.
func GroupByMultipleValues ¶
func GroupByMultipleValues[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) K, valsExtractor func(T) []V) map[K][]V
GroupByMultipleValues converts elements retrieved by the 'next' function into a map, extracting one key, multiple values per each element applying the 'keyExtractor' and 'valsExtractor' functions. The keyExtractor converts an element to a key. The valsExtractor retrieves one or more values per element.
func HasAny ¶
HasAny finds the first element that satisfies the 'predicate' function condition and returns true if successful
func OfIndexed ¶ added in v0.0.8
OfIndexed builds a loop by extracting elements from an indexed soruce. the len is length ot the source. the getAt retrieves an element by its index from the source.
func Range ¶ added in v0.0.8
func Range[T constraints.Integer](from T, toExclusive T) func() (T, bool)
Range creates a loop that generates integers in the range defined by from and to exclusive
func RangeClosed ¶ added in v0.0.8
func RangeClosed[T constraints.Integer](from T, toInclusive T) func() (T, bool)
RangeClosed creates a loop that generates integers in the range defined by from and to inclusive
func Reduce ¶
Reduce reduces the elements retrieved by the 'next' function into an one using the 'merger' function
func SliceCap ¶
SliceCap collects the elements retrieved by the 'next' function into a new slice with predefined capacity
func ToMapResolv ¶
func ToMapResolv[T any, K comparable, V, VR any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V, resolver func(bool, K, VR, V) VR) map[K]VR
ToMapResolv collects key\value elements to a map by iterating over the elements with resolving of duplicated key values
Types ¶
type ConvertCheckIter ¶
type ConvertCheckIter[From, To any] struct { // contains filtered or unexported fields }
ConvertCheckIter converts and filters elements at the same time
func ConvertCheck ¶
func ConvertCheck[From, To any](next func() (From, bool), converter func(from From) (To, bool)) ConvertCheckIter[From, To]
ConvertCheck is similar to ConvertFit, but it checks and transforms elements together
func GetValues ¶
func GetValues[T any](next func() (*T, bool)) ConvertCheckIter[*T, T]
GetValues creates an iterator that transform only not nil pointers to the values referenced referenced by those pointers. Nil pointers are ignored.
func (ConvertCheckIter[From, To]) Next ¶
func (c ConvertCheckIter[From, To]) Next() (t To, ok bool)
Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.
type ConvertFitIter ¶
type ConvertFitIter[From, To any] struct { // contains filtered or unexported fields }
ConvertFitIter iterator implementation that retrieves an element by the 'next' function, converts by the 'converter' and addition checks by the 'filter'. If the filter returns true then the converted element is returned as next.
func ConvertAndFilter ¶
func ConvertAndFilter[From, To any](next func() (From, bool), converter func(From) To, filter func(To) bool) ConvertFitIter[From, To]
ConvertAndFilter additionally filters 'To' elements
func FilterAndConvert ¶
func FilterAndConvert[From, To any](next func() (From, bool), filter func(From) bool, converter func(From) To) ConvertFitIter[From, To]
FilterAndConvert returns a stream that filters source elements and converts them
func FilterConvertFilter ¶
func FilterConvertFilter[From, To any](next func() (From, bool), filter func(From) bool, converter func(From) To, filterTo func(To) bool) ConvertFitIter[From, To]
FilterConvertFilter filters source, converts, and filters converted elements
func (ConvertFitIter[From, To]) For ¶
func (c ConvertFitIter[From, To]) For(walker func(element To) error) error
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (ConvertFitIter[From, To]) ForEach ¶
func (c ConvertFitIter[From, To]) ForEach(walker func(element To))
ForEach FlatIter all elements retrieved by the iterator
func (ConvertFitIter[From, To]) Next ¶
func (c ConvertFitIter[From, To]) Next() (t To, ok bool)
Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.
type ConvertIter ¶
type ConvertIter[From, To any] struct { // contains filtered or unexported fields }
ConvertIter iterator implementation that retrieves an element by the 'next' function and converts by the 'converter'
func Convert ¶
func Convert[From, To any](next func() (From, bool), converter func(From) To) ConvertIter[From, To]
Convert instantiates an iterator that converts elements with a converter and returns them.
func ToValues ¶
func ToValues[T any](next func() (*T, bool)) ConvertIter[*T, T]
ToValues creates an iterator that transform pointers to the values referenced referenced by those pointers. Nil pointers are transformet to zero values.
func (ConvertIter[From, To]) For ¶
func (c ConvertIter[From, To]) For(walker func(element To) error) error
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (ConvertIter[From, To]) ForEach ¶
func (c ConvertIter[From, To]) ForEach(walker func(element To))
ForEach FlatIter all elements retrieved by the iterator
func (ConvertIter[From, To]) Next ¶
func (c ConvertIter[From, To]) Next() (t To, ok bool)
Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.
type FitIter ¶
type FitIter[T any] struct { // contains filtered or unexported fields }
FitIter is the Iterator wrapper that provides filtering of elements by a Predicate.
func Filter ¶
Filter creates an iterator that checks elements by the 'filter' function and returns successful ones.
func (FitIter[T]) For ¶
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
type FlatIter ¶
type FlatIter[From, To any] struct { // contains filtered or unexported fields }
FlatIter is the Iterator wrapper that converts an element to a slice and iterates over the elements of that slice. For example, FlatIter can be used to iterate over all the elements of a multi-dimensional array as if it were a one-dimensional array ([][]int -> []int).
func Flatt ¶
Flatt instantiates an iterator that extracts slices of 'To' by a flattener from elements of 'From' and flattens as one iterable collection of 'To' elements.
func (*FlatIter[From, To]) For ¶
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
type FlattenFitIter ¶
type FlattenFitIter[From, To any] struct { // contains filtered or unexported fields }
FlattenFitIter is the Iterator wrapper that converts an element to a slice with addition filtering of the element by a Predicate and iterates over the slice.
func FilterAndFlatt ¶
func FilterAndFlatt[From, To any](next func() (From, bool), filter func(From) bool, flattener func(From) []To) FlattenFitIter[From, To]
FilterAndFlatt filters source elements and extracts slices of 'To' by the 'flattener' function
func FilterFlattFilter ¶
func FilterFlattFilter[From, To any](next func() (From, bool), filterFrom func(From) bool, flattener func(From) []To, filterTo func(To) bool) FlattenFitIter[From, To]
FilterFlattFilter filters source elements, extracts slices of 'To' by the 'flattener' function and filters extracted elements
func FlattAndFilter ¶
func FlattAndFilter[From, To any](next func() (From, bool), flattener func(From) []To, filterTo func(To) bool) FlattenFitIter[From, To]
FlattAndFilter extracts slices of 'To' by the 'flattener' function and filters extracted elements
func (*FlattenFitIter[From, To]) For ¶
func (i *FlattenFitIter[From, To]) For(walker func(element To) error) error
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (*FlattenFitIter[From, To]) ForEach ¶
func (i *FlattenFitIter[From, To]) ForEach(walker func(element To))
ForEach FlatIter all elements retrieved by the iterator
func (*FlattenFitIter[From, To]) Next ¶
func (i *FlattenFitIter[From, To]) Next() (t To, ok bool)
Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.
type KeyValuer ¶
type KeyValuer[T, K, V any] struct { // contains filtered or unexported fields }
KeyValuer is the Iterator wrapper that converts an element to a key\value pair and iterates over these pairs
func NewKeyValuer ¶
func NewKeyValuer[T any, K, V any](next func() (T, bool), keyExtractor func(T) K, valsExtractor func(T) V) KeyValuer[T, K, V]
NewKeyValuer creates instance of the KeyValuer
func ToKV ¶
func ToKV[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V) KeyValuer[T, K, V]
ToKV transforms iterable elements to key/value iterator based on applying key, value extractors to the elements
func (KeyValuer[T, K, V]) Next ¶
Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.
type MultipleKeyValuer ¶
type MultipleKeyValuer[T, K, V any] struct { // contains filtered or unexported fields }
MultipleKeyValuer is the Iterator wrapper that converts an element to a key\value pair and iterates over these pairs
func FlattKeys ¶
func FlattKeys[T, K, V any](next func() (T, bool), keysExtractor func(T) []K, valExtractor func(T) V) *MultipleKeyValuer[T, K, V]
FlattKeys transforms iterable elements to key/value iterator based on applying key, value extractor to the elements
func FlattValues ¶
func FlattValues[T, K, V any](next func() (T, bool), keyExtractor func(T) K, valsExtractor func(T) []V) *MultipleKeyValuer[T, K, V]
FlattValues transforms iterable elements to key/value iterator based on applying key, value extractor to the elements
func NewMultipleKeyValuer ¶
func NewMultipleKeyValuer[T any, K, V any](next func() (T, bool), keysExtractor func(T) []K, valsExtractor func(T) []V) MultipleKeyValuer[T, K, V]
NewMultipleKeyValuer creates instance of the MultipleKeyValuer
func ToKVs ¶
func ToKVs[T, K, V any](next func() (T, bool), keysExtractor func(T) []K, valsExtractor func(T) []V) *MultipleKeyValuer[T, K, V]
ToKVs transforms iterable elements to key/value iterator based on applying key, value extractor to the elements
func (*MultipleKeyValuer[T, K, V]) Next ¶
func (kv *MultipleKeyValuer[T, K, V]) Next() (key K, value V, ok bool)
Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.
func (*MultipleKeyValuer[T, K, V]) Track ¶
func (kv *MultipleKeyValuer[T, K, V]) Track(traker func(key K, value V) error) error
Track takes key, value pairs retrieved by the iterator. Can be interrupt by returning ErrBreak
func (*MultipleKeyValuer[T, K, V]) TrackEach ¶
func (kv *MultipleKeyValuer[T, K, V]) TrackEach(traker func(key K, value V))
TrackEach takes all key, value pairs retrieved by the iterator
Directories ¶
Path | Synopsis |
---|---|
Package conv provides loop converation helpers
|
Package conv provides loop converation helpers |
Package convert provides loop converation helpers
|
Package convert provides loop converation helpers |
Package filter provides aliases for loop filtering helpers
|
Package filter provides aliases for loop filtering helpers |
Package first provides short aliases for loop functions for retrieving a first element
|
Package first provides short aliases for loop functions for retrieving a first element |
Package flatt provides short aliases for loop functions
|
Package flatt provides short aliases for loop functions |
Package group provides short aliases for functions that are used to group elements retrieved by a loop
|
Package group provides short aliases for functions that are used to group elements retrieved by a loop |
Package range_ provides alias for the slice.Range function
|
Package range_ provides alias for the slice.Range function |
Package sum provides sum.Of alias
|
Package sum provides sum.Of alias |