loop

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package loop provides helpers for loop operation over key/value pairs and iterator implementations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All added in v0.0.12

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

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

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

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

func First added in v0.0.8

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

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

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

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), 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 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

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

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

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

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

func Track added in v0.0.12

func Track[I, T any](next func() (I, T, bool), consumer func(I, T) 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.

func TrackEach added in v0.0.12

func TrackEach[I, T any](next func() (I, T, bool), consumer func(I, T))

TrackEach applies the 'consumer' function to position/element pairs retrieved by the 'next' function

Types

type Loop added in v0.0.12

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

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

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

Crank rertieves next key\value from the 'next' function, returns the function, element, successfully flag.

func Filter

func Filter[K, V any](next func() (K, V, bool), 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 added in v0.0.12

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

New makes a loop from an abstract source

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

func (next Loop[K, V]) All(consumer func(key K, value V) bool)

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

func (next Loop[K, V]) Convert(converter func(K, V) (K, V)) Loop[K, V]

Convert creates a loop that applies the 'converter' function to iterable key\values.

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

func (next Loop[K, V]) ConvertKey(by func(K) K) Loop[K, V]

ConvertKey returns a loop that applies the 'converter' function to keys of the map

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

func (next Loop[K, V]) ConvertValue(converter func(V) V) Loop[K, V]

ConvertValue returns a loop that applies the 'converter' function to values of the map

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

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

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

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]) FilterKey added in v0.0.12

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

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

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

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

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

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

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, bool)

Reduce reduces the elements retrieved by the 'next' function into an one using the 'merge' function.

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, bool, error)

Reducee reduces the elements retrieved by the 'next' function into an one using the 'merge' function.

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