Documentation ¶
Overview ¶
Package loop provides helpers for loop operation over key/value pairs and iterator implementations
Index ¶
- func Conv[K, V any, KOUT, VOUT any](next func() (K, V, bool), converter func(K, V) (KOUT, VOUT, error)) loop.ConvertIter[K, V, KOUT, VOUT]
- func Filt[K, V any](next func() (K, V, bool), filter func(K, V) (bool, error)) loop.FiltIter[K, V]
- func First[K, V any](next func() (K, V, bool), predicate func(K, V) bool) (K, V, bool)
- func Firstt[K, V any](next func() (K, V, bool), predicate func(K, V) (bool, error)) (K, V, bool, error)
- 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 HasAnyy[K, V any](next func() (K, V, bool), predicate func(K, V) (bool, error)) (bool, error)
- func Reduce[K, V any](next func() (K, V, bool), merge func(K, K, V, V) (K, V)) (rk K, rv V)
- func Reducee[K, V any](next func() (K, V, bool), merge func(K, K, V, V) (K, V, error)) (rk K, rv V, err error)
- 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, T any](next func() (K, V, bool), converter func(K, V) T) []T
- type ConvertIter
- type FilterIter
- type Iter
- type Looper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Conv ¶ added in v0.0.8
func Conv[K, V any, KOUT, VOUT any](next func() (K, V, bool), converter func(K, V) (KOUT, VOUT, error)) loop.ConvertIter[K, V, KOUT, VOUT]
Conv creates an iterator that applies a transformer to iterable key\values.
func Filt ¶ added in v0.0.8
Filt creates an iterator that checks elements by a filter and returns successful ones
func First ¶ added in v0.0.8
First returns the first key/value pair that satisfies the condition of the 'predicate' function
func Firstt ¶ added in v0.0.8
func Firstt[K, V any](next func() (K, V, bool), predicate func(K, V) (bool, error)) (K, V, bool, error)
Firstt returns the first key/value pair that satisfies the condition of the 'predicate' function
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 HasAnyy ¶ added in v0.0.8
HasAnyy 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 Reducee ¶ added in v0.0.8
func Reducee[K, V any](next func() (K, V, bool), merge func(K, K, V, V) (K, V, error)) (rk K, rv V, err error)
Reducee 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), converter 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 FilterIter ¶ added in v0.0.9
type FilterIter[K, V any] struct { // contains filtered or unexported fields }
FilterIter is the KVIterator wrapper that provides filtering of key/value elements by a Predicate.
func Filter ¶
func Filter[K, V any](next func() (K, V, bool), filter func(K, V) bool) FilterIter[K, V]
Filter creates an iterator that checks elements by a filter and returns successful ones
func (FilterIter[K, V]) Next ¶ added in v0.0.9
func (f FilterIter[K, V]) Next() (key K, value V, ok bool)
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.
func (FilterIter[K, V]) Track ¶ added in v0.0.9
func (f FilterIter[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 (FilterIter[K, V]) TrackEach ¶ added in v0.0.9
func (f FilterIter[K, V]) TrackEach(traker func(key K, value V))
TrackEach takes all key, value pairs retrieved by the iterator
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.