Documentation ¶
Overview ¶
Package loop provides helpers for loop operation over key/value pairs and iterator implementations
Index ¶
- func Group[K comparable, V any](next func() (K, V, bool)) map[K][]V
- func HasAny[K, V any](next func() (K, V, bool), predicate func(K, V) bool) bool
- func Reduce[K, V any](next func() (K, V, bool), merge func(K, V, K, V) (K, V)) (rk K, rv V)
- func ToMap[K comparable, V any](next func() (K, V, bool)) map[K]V
- func ToMapResolv[K comparable, V, VR any](next func() (K, V, bool), resolver func(bool, K, VR, V) VR) map[K]VR
- func ToSlice[K, V any](next func() (K, V, bool)) []c.KV[K, V]
- type ConvertIter
- type FitKV
- type Iter
- type Looper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Group ¶
func Group[K comparable, V any](next func() (K, V, bool)) map[K][]V
Group collects sets of values grouped by keys obtained by passing a key/value iterator
func HasAny ¶
HasAny finds the first key/value pair that satisfies the 'predicate' function condition and returns true if successful
func Reduce ¶
Reduce reduces the key/value pairs retrieved by the 'next' function into an one pair using the 'merge' function
func ToMap ¶
func ToMap[K comparable, V any](next func() (K, V, bool)) map[K]V
ToMap collects key\value elements to a map by iterating over the elements
func ToMapResolv ¶
func ToMapResolv[K comparable, V, VR any](next func() (K, V, bool), 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 ConvertIter ¶
type ConvertIter[K, V any, K2, V2 any, C func(K, V) (K2, V2)] struct { // contains filtered or unexported fields }
ConvertIter is the iterator wrapper implementation applying a converter to all iterable key/value elements.
func Convert ¶
func Convert[K, V any, k2, v2 any](next func() (K, V, bool), by func(K, V) (k2, v2)) ConvertIter[K, V, k2, v2, func(K, V) (k2, v2)]
Convert creates an iterator that applies a transformer to iterable key\values.
func (ConvertIter[K, V, K2, V2, C]) Next ¶
func (i ConvertIter[K, V, K2, V2, C]) Next() (k2 K2, v2 V2, ok bool)
Next returns the next key/value pair. The ok result indicates whether an pair was returned by the iterator. If ok == false, then the iteration must be completed.
func (ConvertIter[K, V, K2, V2, C]) Track ¶
func (i ConvertIter[K, V, K2, V2, C]) Track(traker func(key K2, value V2) error) error
Track takes key, value pairs retrieved by the iterator. Can be interrupt by returning ErrBreak
func (ConvertIter[K, V, K2, V2, C]) TrackEach ¶
func (i ConvertIter[K, V, K2, V2, C]) TrackEach(traker func(key K2, value V2))
TrackEach takes all key, value pairs retrieved by the iterator
type FitKV ¶
type FitKV[K, V any] struct { // contains filtered or unexported fields }
FitKV is the KVIterator wrapper that provides filtering of key/value elements by a Predicate.
func Filter ¶
Filter creates an iterator that checks elements by a filter and returns successful ones
func (FitKV[K, V]) Next ¶
Next returns the next key/value pair. The ok result indicates whether the pair was returned by the iterator. If ok == false, then the iteration must be completed.
type Iter ¶
type Iter[S, K, V any] struct { // contains filtered or unexported fields }
Iter - universal key\value iterator implementation
func NewIter ¶
func NewIter[S, K, V any](source S, hasNext func(S) bool, getNext func(S) (K, V, error)) Iter[S, K, V]
NewIter creates an Iter instance that loops over key\value elements of a source. The hasNext specifies a predicate that tests existing of a next element in the source. The getNext extracts the one.