Documentation ¶
Overview ¶
Package iter provides implementations of slice based itarators
Index ¶
- func New[TS ~[]T, T any](elements TS) *slice.Iter[T]
- type ConvFiltIter
- type ConvIter
- type ConvertFiltIter
- func (i *ConvertFiltIter[From, To]) Cap() int
- func (i *ConvertFiltIter[From, To]) For(walker func(element To) error) error
- func (i *ConvertFiltIter[From, To]) ForEach(walker func(element To))
- func (i *ConvertFiltIter[From, To]) Next() (t To, ok bool)
- func (i *ConvertFiltIter[From, To]) Start() (*ConvertFiltIter[From, To], To, bool)
- type ConvertIter
- func (i *ConvertIter[From, To]) Cap() int
- func (i *ConvertIter[From, To]) For(walker func(element To) error) error
- func (i *ConvertIter[From, To]) ForEach(walker func(element To))
- func (i *ConvertIter[From, To]) Next() (To, bool)
- func (i *ConvertIter[From, To]) Start() (*ConvertIter[From, To], To, bool)
- type FiltIter
- type FilterIter
- type FlatFiltIter
- type FlatIter
- type FlattIter
- type FlattenFiltIter
- func (f *FlattenFiltIter[From, To]) Cap() int
- func (f *FlattenFiltIter[From, To]) For(walker func(element To) error) error
- func (f *FlattenFiltIter[From, To]) ForEach(walker func(element To))
- func (f *FlattenFiltIter[From, To]) Next() (To, bool)
- func (f *FlattenFiltIter[From, To]) Start() (*FlattenFiltIter[From, To], To, bool)
- type KeyValIter
- type KeyValuerIter
- type MultipleKeyValIter
- type MultipleKeyValuer
- func ExtraKeys[TS ~[]T, T, K, V any](elements TS, keysExtractor func(T) []K, valExtractor func(T) V) *MultipleKeyValuer[T, K, V]
- func ExtraVals[TS ~[]T, T, K, V any](elements TS, keyExtractor func(T) K, valsExtractor func(T) []V) *MultipleKeyValuer[T, K, V]
- func NewMultipleKeyValuer[TS ~[]T, T any, K, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) *MultipleKeyValuer[T, K, V]
- func ToKVs[TS ~[]T, T, K, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) *MultipleKeyValuer[T, K, V]
- func (kv *MultipleKeyValuer[T, K, V]) Next() (key K, value V, ok bool)
- func (kv *MultipleKeyValuer[T, K, V]) Start() (*MultipleKeyValuer[T, K, V], K, V, bool)
- func (kv *MultipleKeyValuer[T, K, V]) Track(traker func(key K, value V) error) error
- func (kv *MultipleKeyValuer[T, K, V]) TrackEach(traker func(key K, value V))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConvFiltIter ¶ added in v0.0.9
type ConvFiltIter[From, To any] struct { // contains filtered or unexported fields }
ConvFiltIter is the array based Iterator thath provides converting of elements by a Converter with addition filtering of the elements by a Predicate.
func FiltAndConv ¶
func FiltAndConv[FS ~[]From, From, To any](elements FS, filter func(From) (bool, error), converter func(From) (To, error)) *ConvFiltIter[From, To]
FiltAndConv additionally filters 'From' elements.
func (*ConvFiltIter[From, To]) Cap ¶ added in v0.0.9
func (i *ConvFiltIter[From, To]) Cap() int
Cap returns the iterator capacity
func (*ConvFiltIter[From, To]) For ¶ added in v0.0.9
func (i *ConvFiltIter[From, To]) For(walker func(element To) error) error
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (*ConvFiltIter[From, To]) Next ¶ added in v0.0.9
func (i *ConvFiltIter[From, To]) Next() (t To, ok bool, err error)
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 (*ConvFiltIter[From, To]) Start ¶ added in v0.0.10
func (i *ConvFiltIter[From, To]) Start() (*ConvFiltIter[From, To], To, bool, error)
Start is used with for loop construct like 'for i, val, ok, err := i.Start(); ok || err != nil ; val, ok, err = i.Next() { if err != nil { return err }}'
type ConvIter ¶
type ConvIter[From, To any] struct { // contains filtered or unexported fields }
ConvIter is the array based Iterator thath provides converting of elements by a ConvIter.
func Conv ¶
func Conv[FS ~[]From, From, To any](elements FS, converter func(From) (To, error)) *ConvIter[From, To]
Conv instantiates an iterator that converts elements with a converter and returns them
func (*ConvIter[From, To]) For ¶
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
type ConvertFiltIter ¶ added in v0.0.9
type ConvertFiltIter[From, To any] struct { // contains filtered or unexported fields }
ConvertFiltIter is the array based Iterator thath provides converting of elements by a Converter with addition filtering of the elements by a Predicate.
func FilterAndConvert ¶
func FilterAndConvert[FS ~[]From, From, To any](elements FS, filter func(From) bool, converter func(From) To) *ConvertFiltIter[From, To]
FilterAndConvert returns a stream that filters source elements and converts them
func (*ConvertFiltIter[From, To]) Cap ¶ added in v0.0.9
func (i *ConvertFiltIter[From, To]) Cap() int
Cap returns the iterator capacity
func (*ConvertFiltIter[From, To]) For ¶ added in v0.0.9
func (i *ConvertFiltIter[From, To]) For(walker func(element To) error) error
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (*ConvertFiltIter[From, To]) ForEach ¶ added in v0.0.9
func (i *ConvertFiltIter[From, To]) ForEach(walker func(element To))
ForEach FlatIter all elements retrieved by the iterator
func (*ConvertFiltIter[From, To]) Next ¶ added in v0.0.9
func (i *ConvertFiltIter[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.
func (*ConvertFiltIter[From, To]) Start ¶ added in v0.0.10
func (i *ConvertFiltIter[From, To]) Start() (*ConvertFiltIter[From, To], To, bool)
Start is used with for loop construct like 'for i, val, ok := i.Start(); ok; val, ok = i.Next() { }'
type ConvertIter ¶
type ConvertIter[From, To any] struct { // contains filtered or unexported fields }
ConvertIter is the array based Iterator thath provides converting of elements by a ConvertIter.
func Convert ¶
func Convert[FS ~[]From, From, To any](elements FS, converter func(From) To) *ConvertIter[From, To]
Convert instantiates an iterator that converts elements with a converter and returns them
func (*ConvertIter[From, To]) Cap ¶
func (i *ConvertIter[From, To]) Cap() int
Cap returns the iterator capacity
func (*ConvertIter[From, To]) For ¶
func (i *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 (i *ConvertIter[From, To]) ForEach(walker func(element To))
ForEach FlatIter all elements retrieved by the iterator
func (*ConvertIter[From, To]) Next ¶
func (i *ConvertIter[From, To]) Next() (To, 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 (*ConvertIter[From, To]) Start ¶ added in v0.0.10
func (i *ConvertIter[From, To]) Start() (*ConvertIter[From, To], To, bool)
Start is used with for loop construct like 'for i, val, ok := i.Start(); ok; val, ok = i.Next() { }'
type FiltIter ¶
type FiltIter[T any] struct { // contains filtered or unexported fields }
FiltIter is the array based Iterator implementation that provides filtering of elements by a Predicate.
func Filt ¶
Filt instantiates an iterator that checks elements by the 'filter' function and returns successful ones
func (*FiltIter[T]) For ¶
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
type FilterIter ¶
type FilterIter[T any] struct { // contains filtered or unexported fields }
FilterIter is the array based Iterator implementation that provides filtering of elements by a Predicate.
func Filter ¶
func Filter[TS ~[]T, T any](elements TS, filter func(T) bool) *FilterIter[T]
Filter instantiates an iterator that checks elements by the 'filter' function and returns successful ones
func NotNil ¶
func NotNil[T any, TRS ~[]*T](elements TRS) *FilterIter[*T]
NotNil instantiates an iterator that filters nullable elements
func (*FilterIter[T]) For ¶
func (f *FilterIter[T]) For(walker func(element T) error) error
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (*FilterIter[T]) ForEach ¶
func (f *FilterIter[T]) ForEach(walker func(element T))
ForEach FlatIter all elements retrieved by the iterator
func (*FilterIter[T]) Next ¶
func (f *FilterIter[T]) Next() (T, 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 (*FilterIter[T]) Start ¶ added in v0.0.10
func (f *FilterIter[T]) Start() (*FilterIter[T], T, bool)
Start is used with for loop construct like 'for i, val, ok := i.Start(); ok; val, ok = i.Next() { }'
type FlatFiltIter ¶
type FlatFiltIter[From, To any] struct { // contains filtered or unexported fields }
FlatFiltIter is the array based Iterator impelementation that converts an element to a slice with addition filtering of the element by a Predicate and iterates over the slice.
func FiltAndFlat ¶
func FiltAndFlat[FS ~[]From, From, To any](elements FS, filter func(From) (bool, error), flattener func(From) ([]To, error)) *FlatFiltIter[From, To]
FiltAndFlat instantiates an iterator that filters elements by the 'filter' function, flattens elements and returns them.
func (*FlatFiltIter[From, To]) Cap ¶
func (f *FlatFiltIter[From, To]) Cap() int
Cap returns the iterator capacity
func (*FlatFiltIter[From, To]) For ¶
func (f *FlatFiltIter[From, To]) For(walker func(element To) error) error
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (*FlatFiltIter[From, To]) Next ¶
func (f *FlatFiltIter[From, To]) Next() (t To, ok bool, err error)
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 (*FlatFiltIter[From, To]) Start ¶ added in v0.0.10
func (f *FlatFiltIter[From, To]) Start() (*FlatFiltIter[From, To], To, bool, error)
Start is used with for loop construct like 'for i, k, v, ok := i.Start(); ok; k, v, ok = i.Next() { }'
type FlatIter ¶
type FlatIter[From, To any] struct { // contains filtered or unexported fields }
FlatIter is the array based Iterator impelementation 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 ¶
func Flatt[FS ~[]From, From, To any](elements FS, flatter func(From) ([]To, error)) *FlatIter[From, To]
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 FlattIter ¶
type FlattIter[From, To any] struct { // contains filtered or unexported fields }
FlattIter is the array based Iterator impelementation that converts an element to a slice and iterates over the elements of that slice. For example, FlattIter 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 Flat ¶
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 (*FlattIter[From, To]) For ¶
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (*FlattIter[From, To]) ForEach ¶
func (f *FlattIter[From, To]) ForEach(walker func(element To))
ForEach FlatIter all elements retrieved by the iterator
type FlattenFiltIter ¶ added in v0.0.9
type FlattenFiltIter[From, To any] struct { // contains filtered or unexported fields }
FlattenFiltIter is the array based Iterator impelementation that converts an element to a slice with addition filtering of the element by a Predicate and iterates over the slice.
func FilterAndFlat ¶ added in v0.0.9
func FilterAndFlat[FS ~[]From, From, To any](elements FS, filter func(From) bool, flattener func(From) []To) *FlattenFiltIter[From, To]
FilterAndFlat filters source elements and extracts slices of 'To' by the 'flattener' function
func (*FlattenFiltIter[From, To]) Cap ¶ added in v0.0.9
func (f *FlattenFiltIter[From, To]) Cap() int
Cap returns the iterator capacity
func (*FlattenFiltIter[From, To]) For ¶ added in v0.0.9
func (f *FlattenFiltIter[From, To]) For(walker func(element To) error) error
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (*FlattenFiltIter[From, To]) ForEach ¶ added in v0.0.9
func (f *FlattenFiltIter[From, To]) ForEach(walker func(element To))
ForEach FlatIter all elements retrieved by the iterator
func (*FlattenFiltIter[From, To]) Next ¶ added in v0.0.9
func (f *FlattenFiltIter[From, To]) Next() (To, 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 (*FlattenFiltIter[From, To]) Start ¶ added in v0.0.10
func (f *FlattenFiltIter[From, To]) Start() (*FlattenFiltIter[From, To], To, bool)
Start is used with for loop construct like 'for i, val, ok := i.Start(); ok; val, ok = i.Next() { }'
type KeyValIter ¶
type KeyValIter[T, K, V any] struct { // contains filtered or unexported fields }
KeyValIter is the Iterator wrapper that converts an element to a key\value pair and iterates over these pairs
func NewKeyVal ¶
func NewKeyVal[TS ~[]T, T any, K, V any](elements TS, keyExtractor func(T) (K, error), valsExtractor func(T) (V, error)) *KeyValIter[T, K, V]
NewKeyVal creates instance of the KeyValuer
func (*KeyValIter[T, K, V]) Next ¶
func (kv *KeyValIter[T, K, V]) Next() (key K, value V, ok bool, err error)
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 (*KeyValIter[T, K, V]) Start ¶ added in v0.0.10
func (kv *KeyValIter[T, K, V]) Start() (*KeyValIter[T, K, V], K, V, bool, error)
Start is used with for loop construct like 'for i, k, v, ok, err := i.Start(); ok || err != nil ; k, v, ok, err = i.Next() { if err != nil { return err }}'
func (KeyValIter[T, K, V]) Track ¶
func (kv KeyValIter[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
type KeyValuerIter ¶
type KeyValuerIter[T, K, V any] struct { // contains filtered or unexported fields }
KeyValuerIter is the Iterator wrapper that converts an element to a key\value pair and iterates over these pairs
func NewKeyValuer ¶
func NewKeyValuer[TS ~[]T, T any, K, V any](elements TS, keyExtractor func(T) K, valsExtractor func(T) V) *KeyValuerIter[T, K, V]
NewKeyValuer creates instance of the KeyValuer
func ToKV ¶
func ToKV[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) *KeyValuerIter[T, K, V]
ToKV transforms iterable elements to key/value iterator based on applying key, value extractors to the elements
func (*KeyValuerIter[T, K, V]) Next ¶
func (kv *KeyValuerIter[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 (*KeyValuerIter[T, K, V]) Start ¶ added in v0.0.10
func (kv *KeyValuerIter[T, K, V]) Start() (*KeyValuerIter[T, K, V], K, V, bool)
Start is used with for loop construct like 'for i, k, v, ok := i.Start(); ok; k, v, ok = i.Next() { }'
func (KeyValuerIter[T, K, V]) Track ¶
func (kv KeyValuerIter[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 (*KeyValuerIter[T, K, V]) TrackEach ¶
func (kv *KeyValuerIter[T, K, V]) TrackEach(traker func(key K, value V))
TrackEach takes all key, value pairs retrieved by the iterator
type MultipleKeyValIter ¶
type MultipleKeyValIter[T, K, V any] struct { // contains filtered or unexported fields }
MultipleKeyValIter is the Iterator wrapper that converts an element to a key\value pair and iterates over these pairs
func NewMultipleKeyVal ¶ added in v0.0.9
func NewMultipleKeyVal[TS ~[]T, T any, K, V any](elements TS, keysExtractor func(T) ([]K, error), valsExtractor func(T) ([]V, error)) *MultipleKeyValIter[T, K, V]
NewMultipleKeyVal creates instance of the KeyValuer
func (*MultipleKeyValIter[T, K, V]) Next ¶
func (kv *MultipleKeyValIter[T, K, V]) Next() (key K, value V, ok bool, err error)
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 (*MultipleKeyValIter[T, K, V]) Start ¶ added in v0.0.10
func (kv *MultipleKeyValIter[T, K, V]) Start() (*MultipleKeyValIter[T, K, V], K, V, bool, error)
Start is used with for loop construct like 'for i, k, v, ok, err := i.Start(); ok || err != nil ; k, v, ok, err = i.Next() { if err != nil { return err }}'
func (*MultipleKeyValIter[T, K, V]) Track ¶
func (kv *MultipleKeyValIter[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
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 ExtraKeys ¶ added in v0.0.10
func ExtraKeys[TS ~[]T, T, K, V any](elements TS, keysExtractor func(T) []K, valExtractor func(T) V) *MultipleKeyValuer[T, K, V]
ExtraKeys transforms iterable elements to key/value iterator based on applying key, value extractor to the elements
func ExtraVals ¶ added in v0.0.10
func ExtraVals[TS ~[]T, T, K, V any](elements TS, keyExtractor func(T) K, valsExtractor func(T) []V) *MultipleKeyValuer[T, K, V]
ExtraVals transforms iterable elements to key/value iterator based on applying key, value extractor to the elements
func NewMultipleKeyValuer ¶
func NewMultipleKeyValuer[TS ~[]T, T any, K, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) *MultipleKeyValuer[T, K, V]
NewMultipleKeyValuer creates instance of the MultipleKeyValuer
func ToKVs ¶
func ToKVs[TS ~[]T, T, K, V any](elements TS, 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]) Start ¶ added in v0.0.10
func (kv *MultipleKeyValuer[T, K, V]) Start() (*MultipleKeyValuer[T, K, V], K, V, bool)
Start is used with for loop construct like 'for i, k, v, ok := i.Start(); ok; k, v, ok = i.Next() { }'
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