Documentation ¶
Overview ¶
Package loop provides helpers for loop operation over key/value pairs and iterator implementations
Index ¶
- func All[K, V any](next func() (K, V, bool), consumer func(K, V) bool)
- func Conv[K, V any, KOUT, VOUT any](next func() (K, V, bool), converter func(K, V) (KOUT, VOUT, error)) loop.Loop[KOUT, VOUT]
- func Filt[K, V any](next func() (K, V, bool), filter func(K, V) (bool, error)) loop.Loop[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 Map[K comparable, V any](next func() (K, V, bool)) map[K]V
- func MapResolv[K comparable, V, VR any](next func() (K, V, bool), resolver func(bool, K, VR, V) VR) map[K]VR
- func Reduce[K, V any](next func() (K, V, bool), merge func(K, K, V, V) (K, V)) (rk K, rv V)
- func ReduceOK[K, V any](next func() (K, V, bool), merge func(K, K, V, V) (K, V)) (rk K, rv V, ok bool)
- 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 ReduceeOK[K, V any](next func() (K, V, bool), merge func(K, K, V, V) (K, V, error)) (rk K, rv V, ok bool, err error)
- func Slice[K, V, T any](next func() (K, V, bool), converter func(K, V) T) []T
- func Track[I, T any](next func() (I, T, bool), consumer func(I, T) error) error
- func TrackEach[I, T any](next func() (I, T, bool), consumer func(I, T))
- type Loop
- func Convert[K, V any, KOUT, VOUT any](next func() (K, V, bool), converter func(K, V) (KOUT, VOUT)) Loop[KOUT, VOUT]
- func Crank[K, V any](next func() (K, V, bool)) (n Loop[K, V], k K, v V, ok bool)
- func Filter[K, V any](next func() (K, V, bool), 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)) Loop[K, V]
- func (next Loop[K, V]) All(consumer func(key K, value V) bool)
- func (next Loop[K, V]) Conv(converter func(K, V) (K, V, error)) breakkvloop.Loop[K, V]
- func (next Loop[K, V]) ConvKey(converter func(K) (K, error)) breakkvloop.Loop[K, V]
- func (next Loop[K, V]) ConvValue(converter func(V) (V, error)) breakkvloop.Loop[K, V]
- func (next Loop[K, V]) Convert(converter func(K, V) (K, V)) Loop[K, V]
- func (next Loop[K, V]) ConvertKey(by func(K) K) Loop[K, V]
- func (next Loop[K, V]) ConvertValue(converter func(V) V) Loop[K, V]
- func (next Loop[K, V]) Crank() (Loop[K, V], K, V, bool)
- func (next Loop[K, V]) Filt(filter func(K, V) (bool, error)) breakkvloop.Loop[K, V]
- func (next Loop[K, V]) FiltKey(predicate func(K) (bool, error)) breakkvloop.Loop[K, V]
- func (next Loop[K, V]) FiltValue(predicate func(V) (bool, error)) breakkvloop.Loop[K, V]
- func (next Loop[K, V]) Filter(filter func(K, V) bool) Loop[K, V]
- func (next Loop[K, V]) FilterKey(predicate func(K) bool) Loop[K, V]
- func (next Loop[K, V]) FilterValue(predicate func(V) bool) Loop[K, V]
- func (next Loop[K, V]) First(predicate func(K, V) bool) (K, V, bool)
- func (next Loop[K, V]) HasAny(predicate func(K, V) bool) bool
- func (next Loop[K, V]) Reduce(merge func(K, K, V, V) (K, V)) (K, V, bool)
- func (next Loop[K, V]) Reducee(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 All ¶ added in v0.0.12
All is an adapter for the next function for iterating by `for ... range`. Supported since go 1.22 with GOEXPERIMENT=rangefunc enabled.
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.Loop[KOUT, VOUT]
Conv creates a loop that applies the 'converter' function to iterable key\values.
func Filt ¶ added in v0.0.8
Filt creates a loop that checks elements by the 'filter' function 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 Map ¶ added in v0.0.14
func Map[K comparable, V any](next func() (K, V, bool)) map[K]V
Map collects key\value elements into a new map by iterating over the elements
func MapResolv ¶ added in v0.0.14
func MapResolv[K comparable, V, VR any](next func() (K, V, bool), resolver func(bool, K, VR, V) VR) map[K]VR
MapResolv collects key\value elements into a new map by iterating over the elements with resolving of duplicated key values
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), merge func(K, K, V, V) (K, V)) (rk K, rv V, ok bool)
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), 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. 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), 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 Slice ¶ added in v0.0.14
Slice collects key\value elements to a slice by iterating over the elements
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 Convert ¶
func Convert[K, V any, KOUT, VOUT any](next func() (K, V, bool), 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 next key\value from the 'next' function, returns the function, element, successfully flag.
func Filter ¶
Filter creates a loop that checks elements by the 'filter' function and returns successful ones.
func (Loop[K, V]) All ¶ added in v0.0.12
All is used to iterate through the loop using `for ... range`. Supported since go 1.22 with GOEXPERIMENT=rangefunc enabled.
func (Loop[K, V]) Conv ¶ added in v0.0.12
func (next Loop[K, V]) Conv(converter func(K, V) (K, V, error)) breakkvloop.Loop[K, V]
Conv creates a loop that applies the 'converter' function to iterable key\values.
func (Loop[K, V]) ConvKey ¶ added in v0.0.12
func (next Loop[K, V]) ConvKey(converter func(K) (K, error)) breakkvloop.Loop[K, V]
ConvKey returns a loop that applies the 'converter' function to keys of the map
func (Loop[K, V]) ConvValue ¶ added in v0.0.12
func (next Loop[K, V]) ConvValue(converter func(V) (V, error)) breakkvloop.Loop[K, V]
ConvValue returns a breakable loop that applies the 'converter' function to values of the map
func (Loop[K, V]) Convert ¶ added in v0.0.12
Convert creates a loop that applies the 'converter' function to iterable key\values.
func (Loop[K, V]) ConvertKey ¶ added in v0.0.12
ConvertKey returns a loop that applies the 'converter' function to keys of the map
func (Loop[K, V]) ConvertValue ¶ added in v0.0.12
ConvertValue returns a loop that applies the 'converter' function to values of the map
func (Loop[K, V]) Crank ¶ added in v0.0.12
Crank rertieves a next element from the 'next' function, returns the function, element, successfully flag.
func (Loop[K, V]) Filt ¶ added in v0.0.12
func (next Loop[K, V]) Filt(filter func(K, V) (bool, error)) breakkvloop.Loop[K, V]
Filt creates a loop that checks elements by the 'filter' function and returns successful ones.
func (Loop[K, V]) FiltKey ¶ added in v0.0.12
func (next Loop[K, V]) FiltKey(predicate func(K) (bool, error)) breakkvloop.Loop[K, V]
FiltKey returns a loop consisting of key/value pairs where the key satisfies the condition of the 'predicate' function
func (Loop[K, V]) FiltValue ¶ added in v0.0.12
func (next Loop[K, V]) FiltValue(predicate func(V) (bool, error)) breakkvloop.Loop[K, V]
FiltValue returns a breakable loop consisting of key/value pairs where the value satisfies the condition of the 'predicate' function
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]) FilterKey ¶ added in v0.0.12
FilterKey returns a loop consisting of key/value pairs where the key satisfies the condition of the 'predicate' function
func (Loop[K, V]) FilterValue ¶ added in v0.0.12
FilterValue returns a loop consisting of key/value pairs where the value satisfies the condition of the 'predicate' function
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 elements retrieved by the 'next' function into an one using the 'merge' function.