Documentation ¶
Overview ¶
Package loop provides helpers for loop operation over key/value pairs.
Index ¶
- func First[K, V any](next func() (K, V, bool, error), predicate func(K, V) bool) (K, V, bool, error)
- func Firstt[K, V any](next func() (K, V, bool, error), predicate func(K, V) (bool, error)) (K, V, bool, error)
- func From[K, V any](next func() (K, V, bool)) func() (K, V, bool, error)
- func Group[K comparable, V any](next func() (K, V, bool, error)) (map[K][]V, error)
- func HasAny[K, V any](next func() (K, V, bool, error), predicate func(K, V) bool) (bool, error)
- func HasAnyy[K, V any](next func() (K, V, bool, error), predicate func(K, V) (bool, error)) (bool, error)
- func Reduce[K, V any](next func() (K, V, bool, error), merge func(K, K, V, V) (K, V)) (K, V, error)
- func ReduceOK[K, V any](next func() (K, V, bool, error), merge func(K, K, V, V) (K, V)) (rk K, rv V, ok bool, err error)
- func Reducee[K, V any](next func() (K, V, bool, error), merge func(K, K, V, V) (K, V, error)) (K, V, error)
- func ReduceeOK[K, V any](next func() (K, V, bool, error), merge func(K, K, V, V) (K, V, error)) (rk K, rv V, ok bool, err error)
- func To[K, V any](next func() (K, V, bool, error), errConsumer func(error)) func() (K, V, bool)
- func ToMap[K comparable, V any](next func() (K, V, bool, error)) (map[K]V, error)
- func ToMapResolv[K comparable, V, VR any](next func() (K, V, bool, error), resolver func(bool, K, VR, V) VR) (map[K]VR, error)
- func ToSlice[K, V, T any](next func() (K, V, bool, error), converter func(K, V) T) ([]T, error)
- func Track[K, V any](next func() (K, V, bool, error), consumer func(K, V) error) error
- type Loop
- func Conv[K, V any, KOUT, VOUT any](next func() (K, V, bool, error), converter func(K, V) (KOUT, VOUT, error)) Loop[KOUT, VOUT]
- func Convert[K, V any, KOUT, VOUT any](next func() (K, V, bool, error), converter func(K, V) (KOUT, VOUT)) Loop[KOUT, VOUT]
- func Crank[K, V any](next func() (K, V, bool, error)) (n Loop[K, V], k K, v V, ok bool, err error)
- func Filt[K, V any](next func() (K, V, bool, error), filter func(K, V) (bool, error)) Loop[K, V]
- func Filter[K, V any](next func() (K, V, bool, error), filter func(K, V) bool) Loop[K, V]
- func New[S, K, V any](source S, hasNext func(S) bool, getNext func(S) (K, V, error)) Loop[K, V]
- func (next Loop[K, V]) Crank() (Loop[K, V], K, V, bool, error)
- func (next Loop[K, V]) Filt(filter func(K, V) (bool, error)) Loop[K, V]
- func (next Loop[K, V]) Filter(filter func(K, V) bool) Loop[K, V]
- func (next Loop[K, V]) First(predicate func(K, V) bool) (K, V, bool, error)
- func (next Loop[K, V]) HasAny(predicate func(K, V) bool) (bool, error)
- func (next Loop[K, V]) Reduce(merge func(K, K, V, V) (K, V)) (K, V, error)
- func (next Loop[K, V]) ReduceOK(merge func(K, K, V, V) (K, V)) (K, V, bool, error)
- func (next Loop[K, V]) Reducee(merge func(K, K, V, V) (K, V, error)) (K, V, error)
- func (next Loop[K, V]) ReduceeOK(merge func(K, K, V, V) (K, V, error)) (K, V, bool, error)
- func (next Loop[K, V]) Track(consumer func(K, V) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func First ¶ added in v0.0.8
func First[K, V any](next func() (K, V, bool, error), predicate func(K, V) bool) (K, V, bool, error)
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, error), 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, error)) (map[K][]V, error)
Group collects sets of values grouped by keys obtained by passing a key/value loop.
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
func HasAnyy[K, V any](next func() (K, V, bool, error), predicate func(K, V) (bool, error)) (bool, error)
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. If the 'next' function returns ok=false at the first call, the zero values of 'K', 'V' types are returned.
func ReduceOK ¶ added in v0.0.13
func ReduceOK[K, V any](next func() (K, V, bool, error), merge func(K, K, V, V) (K, V)) (rk K, rv V, ok bool, err error)
ReduceOK reduces the key/value pairs retrieved by the 'next' function into an one pair using the 'merge' function. Returns ok==false if the 'next' function returns ok=false at the first call (no more elements).
func Reducee ¶ added in v0.0.8
func Reducee[K, V any](next func() (K, V, bool, error), merge func(K, K, V, V) (K, V, error)) (K, V, error)
Reducee reduces the key/value pairs retrieved by the 'next' function into an one pair using the 'merge' function. If the 'next' function returns ok=false at the first call, the zero values of 'K', 'V' types are returned.
func ReduceeOK ¶ added in v0.0.13
func ReduceeOK[K, V any](next func() (K, V, bool, error), merge func(K, K, V, V) (K, V, error)) (rk K, rv V, ok bool, err error)
ReduceeOK reduces the key/value pairs retrieved by the 'next' function into an one pair using the 'merge' function. Returns ok==false if the 'next' function returns ok=false at the first call (no more elements).
func To ¶
To transforms a breakable loop to a simple loop. The errConsumer is a function that is called when an error occurs.
func ToMap ¶
func ToMap[K comparable, V any](next func() (K, V, bool, error)) (map[K]V, error)
ToMap collects key\value elements into a new map by iterating over the elements
func ToMapResolv ¶
func ToMapResolv[K comparable, V, VR any](next func() (K, V, bool, error), resolver func(bool, K, VR, V) VR) (map[K]VR, error)
ToMapResolv collects key\value elements into a new map by iterating over the elements with resolving of duplicated key values
Types ¶
type Loop ¶ added in v0.0.12
Loop is a function that returns the next key\value or ok==false if there are no more elements.
func Conv ¶
func Conv[K, V any, KOUT, VOUT any](next func() (K, V, bool, error), converter func(K, V) (KOUT, VOUT, error)) Loop[KOUT, VOUT]
Conv creates a loop that applies the 'converter' function to iterable key\values.
func Convert ¶
func Convert[K, V any, KOUT, VOUT any](next func() (K, V, bool, error), converter func(K, V) (KOUT, VOUT)) Loop[KOUT, VOUT]
Convert creates a loop that applies the 'converter' function to iterable key\values.
func Crank ¶ added in v0.0.12
Crank rertieves a next element from the 'next' function, returns the function, element, successfully flag.
func Filt ¶
Filt creates a loop that checks elements by the 'filter' function and returns successful ones.
func Filter ¶
Filter creates a loop that checks elements by the 'filter' function and returns successful ones.
func (Loop[K, V]) Crank ¶ added in v0.0.12
Crank rertieves next key\value elements from the 'next' function, returns the function, element, successfully flag.
func (Loop[K, V]) Filt ¶ added in v0.0.12
Filt creates a loop that checks elements by the 'filter' function and returns successful ones.
func (Loop[K, V]) Filter ¶ added in v0.0.12
Filter creates a loop that checks elements by the 'filter' function and returns successful ones.
func (Loop[K, V]) First ¶ added in v0.0.12
First returns the first element that satisfies the condition of the 'predicate' function
func (Loop[K, V]) HasAny ¶ added in v0.0.12
HasAny finds the first element that satisfies the 'predicate' function condition and returns true if successful
func (Loop[K, V]) Reduce ¶ added in v0.0.12
Reduce reduces the key/value pairs retrieved by the 'next' function into an one pair using the 'merge' function. If the 'next' function returns ok=false at the first call, the zero values of 'K', 'V' types are returned.
func (Loop[K, V]) ReduceOK ¶ added in v0.0.13
ReduceOK reduces the key/value pairs retrieved by the 'next' function into an one pair using the 'merge' function. Returns ok==false if the 'next' function returns ok=false at the first call (no more elements).
func (Loop[K, V]) Reducee ¶ added in v0.0.12
Reducee reduces the key/value pairs retrieved by the 'next' function into an one pair using the 'merge' function. If the 'next' function returns ok=false at the first call, the zero values of 'K', 'V' types are returned.