loop

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package loop provides helpers for loop operation over key/value pairs.

Index

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 From

func From[K, V any](next func() (K, V, bool)) func() (K, V, bool, error)

From wrap the next loop to a breakable loop

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

func HasAny[K, V any](next func() (K, V, bool, error), predicate func(K, V) bool) (bool, error)

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

func Reduce[K, V any](next func() (K, V, bool, error), merge func(K, K, V, V) (K, V)) (K, V, error)

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

func To[K, V any](next func() (K, V, bool, error), errConsumer func(error)) func() (K, V, bool)

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

func ToSlice

func ToSlice[K, V, T any](next func() (K, V, bool, error), converter func(K, V) T) ([]T, error)

ToSlice collects key\value elements to a slice by iterating over the elements

func Track added in v0.0.12

func Track[K, V any](next func() (K, V, bool, error), consumer func(K, V) error) error

Track applies the 'consumer' function to position/element pairs retrieved by the 'next' function until the consumer returns the c.Break to stop.

Types

type Loop added in v0.0.12

type Loop[K, V any] func() (key K, value V, ok bool, error error)

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

func Crank[K, V any](next func() (K, V, bool, error)) (n Loop[K, V], k K, v V, ok bool, err error)

Crank rertieves a next element from the 'next' function, returns the function, element, successfully flag.

func Filt

func Filt[K, V any](next func() (K, V, bool, error), filter func(K, V) (bool, error)) Loop[K, V]

Filt creates a loop that checks elements by the 'filter' function and returns successful ones.

func Filter

func Filter[K, V any](next func() (K, V, bool, error), filter func(K, V) bool) Loop[K, V]

Filter creates a loop that checks elements by the 'filter' function and returns successful ones.

func New

func New[S, K, V any](source S, hasNext func(S) bool, getNext func(S) (K, V, error)) Loop[K, V]

New is the mai breakable key/value loop constructor

func (Loop[K, V]) Crank added in v0.0.12

func (next Loop[K, V]) Crank() (Loop[K, V], K, V, bool, error)

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

func (next Loop[K, V]) Filt(filter func(K, V) (bool, error)) Loop[K, V]

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

func (next Loop[K, V]) Filter(filter func(K, V) bool) Loop[K, V]

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

func (next Loop[K, V]) First(predicate func(K, V) bool) (K, V, bool, error)

First returns the first element that satisfies the condition of the 'predicate' function

func (Loop[K, V]) HasAny added in v0.0.12

func (next Loop[K, V]) HasAny(predicate func(K, V) bool) (bool, error)

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

func (next Loop[K, V]) Reduce(merge func(K, K, V, V) (K, V)) (K, V, error)

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

func (next Loop[K, V]) ReduceOK(merge func(K, K, V, V) (K, V)) (K, V, bool, 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 (Loop[K, V]) Reducee added in v0.0.12

func (next Loop[K, V]) Reducee(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 (Loop[K, V]) ReduceeOK added in v0.0.13

func (next Loop[K, V]) ReduceeOK(merge func(K, K, V, V) (K, V, error)) (K, V, bool, 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 (Loop[K, V]) Track added in v0.0.12

func (next Loop[K, V]) Track(consumer func(K, V) error) error

Track applies the 'consumer' function to position/element pairs retrieved by the 'next' function until the consumer returns the c.Break to stop.

Directories

Path Synopsis
Package group provides short aliases for functions thath are used to group key/value pairs retrieved by a loop
Package group provides short aliases for functions thath are used to group key/value pairs retrieved by a loop

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL