Documentation ¶
Overview ¶
Package loop provides helpers for loop operation and iterator implementations
Index ¶
- Variables
- func Accum[T any](first T, next func() (T, bool), merge func(T, T) T) T
- func Accumm[T any](first T, next func() (T, bool), merge func(T, T) (T, error)) (accumulator T, err error)
- func All[T any](next func() (T, bool), consumer func(T) bool)
- func Append[T any, TS ~[]T](next func() (T, bool), out TS) TS
- func AppendMapResolv[T any, K comparable, V, VR any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V, ...) map[K]VR
- func AppendMapResolvOrder[T any, K comparable, V, VR any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V, ...) ([]K, map[K]VR)
- func Contains[T comparable](next func() (T, bool), example T) bool
- func Conv[From, To any](next func() (From, bool), converter func(From) (To, error)) breakloop.Loop[To]
- func ConvAndReduce[From, To any](next func() (From, bool), converter func(From) (To, error), ...) (out To, err error)
- func ConvOK[From, To any](next func() (From, bool), converter func(from From) (To, bool, error)) breakloop.Loop[To]
- func ConvS[FS ~[]From, From, To any](elements FS, converter func(From) (To, error)) breakloop.Loop[To]
- func ConvertAndReduce[From, To any](next func() (From, bool), converter func(From) To, merge func(To, To) To) (out To)
- func ExtraKey[T, K any](next func() (T, bool), keysExtractor func(T) K) kvloop.Loop[K, T]
- func ExtraKeys[T, K any](next func() (T, bool), keysExtractor func(T) []K) kvloop.Loop[K, T]
- func ExtraKeyss[T, K any](next func() (T, bool), keyExtractor func(T) (K, error)) breakkvloop.Loop[K, T]
- func ExtraKeyy[T, K any](next func() (T, bool), keyExtractor func(T) (K, error)) breakkvloop.Loop[K, T]
- func ExtraVals[T, V any](next func() (T, bool), valsExtractor func(T) []V) kvloop.Loop[T, V]
- func ExtraValss[T, V any](next func() (T, bool), valsExtractor func(T) ([]V, error)) breakkvloop.Loop[T, V]
- func ExtraValue[T, V any](next func() (T, bool), valueExtractor func(T) V) kvloop.Loop[T, V]
- func ExtraValuee[T, V any](next func() (T, bool), valExtractor func(T) (V, error)) breakkvloop.Loop[T, V]
- func Filt[T any](next func() (T, bool), filter func(T) (bool, error)) breakloop.Loop[T]
- func FiltAndConv[From, To any](next func() (From, bool), filter func(From) (bool, error), ...) breakloop.Loop[To]
- func FiltAndFlat[From, To any](next func() (From, bool), filter func(From) (bool, error), ...) breakloop.Loop[To]
- func FiltFlattFilt[From, To any](next func() (From, bool), filterFrom func(From) (bool, error), ...) breakloop.Loop[To]
- func FiltS[TS ~[]T, T any](elements TS, filter func(T) (bool, error)) breakloop.Loop[T]
- func First[T any](next func() (T, bool), predicate func(T) bool) (v T, ok bool)
- func Firstt[T any](next func() (T, bool), predicate func(T) (bool, error)) (v T, ok bool, err error)
- func FlatAndFilt[From, To any](next func() (From, bool, error), flattener func(From) ([]To, error), ...) breakloop.Loop[To]
- func Flatt[From, To any](next func() (From, bool), flattener func(From) ([]To, error)) breakloop.Loop[To]
- func FlattS[FS ~[]From, From, To any](elements FS, flattener func(From) ([]To, error)) breakloop.Loop[To]
- func For[T any](next func() (T, bool), consumer func(T) error) error
- func ForEach[T any](next func() (T, bool), consumer func(T))
- func ForEachFiltered[T any](next func() (T, bool), predicate func(T) bool, consumer func(T))
- func Group[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V) map[K][]V
- func GroupByMultiple[T any, K comparable, V any](next func() (T, bool), keysExtractor func(T) []K, valsExtractor func(T) []V) map[K][]V
- func GroupByMultipleKeys[T any, K comparable, V any](next func() (T, bool), keysExtractor func(T) []K, valExtractor func(T) V) map[K][]V
- func GroupByMultipleValues[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) K, valsExtractor func(T) []V) map[K][]V
- func Groupp[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) (K, error), ...) (map[K][]V, error)
- func HasAny[T any](next func() (T, bool), predicate func(T) bool) bool
- func KeyValue[T any, K, V any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V) kvloop.Loop[K, V]
- func KeyValuee[T any, K, V any](next func() (T, bool), keyExtractor func(T) (K, error), ...) breakkvloop.Loop[K, V]
- func KeyValues[T, K, V any](next func() (T, bool), keyExtractor func(T) K, valsExtractor func(T) []V) kvloop.Loop[K, V]
- func KeyValuess[T, K, V any](next func() (T, bool), keyExtractor func(T) (K, error), ...) breakkvloop.Loop[K, V]
- func KeysValue[T, K, V any](next func() (T, bool), keysExtractor func(T) []K, valExtractor func(T) V) kvloop.Loop[K, V]
- func KeysValuee[T, K, V any](next func() (T, bool), keysExtractor func(T) ([]K, error), ...) breakkvloop.Loop[K, V]
- func KeysValues[T, K, V any](next func() (T, bool), keysExtractor func(T) []K, valsExtractor func(T) []V) kvloop.Loop[K, V]
- func Reduce[T any](next func() (T, bool), merge func(T, T) T) T
- func ReduceOK[T any](next func() (T, bool), merge func(T, T) T) (result T, ok bool)
- func Reducee[T any](next func() (T, bool), merge func(T, T) (T, error)) (T, error)
- func ReduceeOK[T any](next func() (T, bool), merge func(T, T) (T, error)) (result T, ok bool, err error)
- func Slice[T any](next func() (T, bool)) []T
- func SliceCap[T any](next func() (T, bool), cap int) (out []T)
- func Sum[T c.Summable](next func() (T, bool)) (out T)
- func ToMap[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V) map[K]V
- func ToMapResolv[T any, K comparable, V, VR any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V, ...) map[K]VR
- func ToMapResolvOrder[TS ~[]T, T any, K comparable, V, VR any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V, ...) ([]K, map[K]VR)
- func ToMapp[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) (K, error), ...) (map[K]V, error)
- 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[From, To any](next func() (From, bool), converter func(From) To) Loop[To]
- func ConvertAndFilter[From, To any](next func() (From, bool), converter func(From) To, filter func(To) bool) Loop[To]
- func ConvertOK[From, To any](next func() (From, bool), converter func(from From) (To, bool)) Loop[To]
- func ConvertS[FS ~[]From, From, To any](elements FS, converter func(From) To) Loop[To]
- func Crank[T any](next func() (T, bool)) (n Loop[T], t T, ok bool)
- func Filter[T any](next func() (T, bool), filter func(T) bool) Loop[T]
- func FilterAndConvert[From, To any](next func() (From, bool), filter func(From) bool, converter func(From) To) Loop[To]
- func FilterAndFlat[From, To any](next func() (From, bool), filter func(From) bool, flattener func(From) []To) Loop[To]
- func FilterConvertFilter[From, To any](next func() (From, bool), filter func(From) bool, converter func(From) To, ...) Loop[To]
- func FilterFlatFilter[From, To any](next func() (From, bool), filterFrom func(From) bool, ...) Loop[To]
- func FilterS[TS ~[]T, T any](elements TS, filter func(T) bool) Loop[T]
- func Flat[From, To any](next func() (From, bool), flattener func(From) []To) Loop[To]
- func FlatS[FS ~[]From, From, To any](elements FS, flattener func(From) []To) Loop[To]
- func FlattAndFilter[From, To any](next func() (From, bool), flattener func(From) []To, filterTo func(To) bool) Loop[To]
- func New[S, T any](source S, hasNext func(S) bool, getNext func(S) T) Loop[T]
- func NoNilPtrVal[T any](next func() (*T, bool)) Loop[T]
- func NotNil[T any](next func() (*T, bool)) Loop[*T]
- func Of[T any](elements ...T) Loop[T]
- func OfIndexed[T any](len int, next func(int) T) Loop[T]
- func PtrVal[T any](next func() (*T, bool)) Loop[T]
- func Range[T constraints.Integer | rune](from T, toExclusive T) Loop[T]
- func RangeClosed[T constraints.Integer | rune](from T, toInclusive T) Loop[T]
- func S[TS ~[]T, T any](elements TS) Loop[T]
- func Sequence[T any](first T, next func(T) (T, bool)) Loop[T]
- func (next Loop[T]) Accum(first T, merge func(T, T) T) T
- func (next Loop[T]) Accumm(first T, merge func(T, T) (T, error)) (T, error)
- func (next Loop[T]) All(consumer func(T) bool)
- func (next Loop[T]) Append(out []T) []T
- func (next Loop[T]) Conv(converter func(T) (T, error)) loop.Loop[T]
- func (next Loop[T]) Convert(converter func(T) T) Loop[T]
- func (next Loop[T]) Crank() (Loop[T], T, bool)
- func (next Loop[T]) Filt(filter func(T) (bool, error)) loop.Loop[T]
- func (next Loop[T]) Filter(filter func(T) bool) Loop[T]
- func (next Loop[T]) First(predicate func(T) bool) (T, bool)
- func (next Loop[T]) For(consumer func(T) error) error
- func (next Loop[T]) ForEach(consumer func(T))
- func (next Loop[T]) ForEachFiltered(predicate func(T) bool, consumer func(T))
- func (next Loop[T]) HasAny(predicate func(T) bool) bool
- func (next Loop[T]) Reduce(merge func(T, T) T) T
- func (next Loop[T]) ReduceOK(merge func(T, T) T) (result T, ok bool)
- func (next Loop[T]) Reducee(merge func(T, T) (T, error)) (T, error)
- func (next Loop[T]) ReduceeOK(merge func(T, T) (T, error)) (resul T, ok bool, err error)
- func (next Loop[T]) Slice() []T
- func (next Loop[T]) SliceCap(cap int) []T
Constants ¶
This section is empty.
Variables ¶
var Break = c.Break
Break is the 'break' statement of the For, Track methods.
var Continue = c.Continue
Continue is an alias of the nil value used to continue iterating by For, Track methods.
Functions ¶
func Accum ¶ added in v0.0.13
Accum accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element retrieved by the 'next' function.
func Accumm ¶ added in v0.0.13
func Accumm[T any](first T, next func() (T, bool), merge func(T, T) (T, error)) (accumulator T, err error)
Accumm accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element retrieved by the 'next' function.
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 Append ¶
Append collects the elements retrieved by the 'next' function into the specified 'out' slice
func AppendMapResolv ¶ added in v0.0.13
func AppendMapResolv[T any, K comparable, V, VR any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V, resolver func(bool, K, VR, V) VR, dest map[K]VR) map[K]VR
AppendMapResolv collects key\value elements into the 'dest' map by iterating over the elements with resolving of duplicated key values
func AppendMapResolvOrder ¶ added in v0.0.13
func AppendMapResolvOrder[T any, K comparable, V, VR any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V, resolver func(bool, K, VR, V) VR, order []K, dest map[K]VR) ([]K, map[K]VR)
AppendMapResolvOrder collects key\value elements into the 'dest' map by iterating over the elements with resolving of duplicated key values Additionaly populates the 'order' slice by the keys ordered by the time they were added and the resolved key\value map.
func Contains ¶
func Contains[T comparable](next func() (T, bool), example T) bool
Contains finds the first element that equal to the example and returns true
func Conv ¶ added in v0.0.8
func Conv[From, To any](next func() (From, bool), converter func(From) (To, error)) breakloop.Loop[To]
Conv creates a loop that applies the 'converter' function to iterable elements.
func ConvAndReduce ¶ added in v0.0.8
func ConvAndReduce[From, To any](next func() (From, bool), converter func(From) (To, error), merge func(To, To) To) (out To, err error)
ConvAndReduce converts each elements and merges them into one
func ConvOK ¶ added in v0.0.13
func ConvOK[From, To any](next func() (From, bool), converter func(from From) (To, bool, error)) breakloop.Loop[To]
ConvOK creates a loop that applies the 'converter' function to iterable elements. The converter may returns a value or ok=false to exclude the value from the loop. It may also return an error to abort the loop.
func ConvS ¶ added in v0.0.12
func ConvS[FS ~[]From, From, To any](elements FS, converter func(From) (To, error)) breakloop.Loop[To]
ConvS creates a loop that applies the 'converter' function to the 'elements' slice.
func ConvertAndReduce ¶ added in v0.0.8
func ConvertAndReduce[From, To any](next func() (From, bool), converter func(From) To, merge func(To, To) To) (out To)
ConvertAndReduce converts each elements and merges them into one
func ExtraKey ¶ added in v0.0.10
ExtraKey transforms a loop to the key/value loop based on applying key extractor to the elements
func ExtraKeys ¶ added in v0.0.10
ExtraKeys transforms a loop to the key/value loop based on applying key extractor to the elements
func ExtraKeyss ¶ added in v0.0.10
func ExtraKeyss[T, K any](next func() (T, bool), keyExtractor func(T) (K, error)) breakkvloop.Loop[K, T]
ExtraKeyss transforms a loop to the key/value loop based on applying key extractor to the elements
func ExtraKeyy ¶ added in v0.0.10
func ExtraKeyy[T, K any](next func() (T, bool), keyExtractor func(T) (K, error)) breakkvloop.Loop[K, T]
ExtraKeyy transforms a loop to the key/value loop based on applying key extractor to the elements
func ExtraVals ¶ added in v0.0.10
ExtraVals transforms a loop to the key/value loop based on applying values extractor to the elements
func ExtraValss ¶ added in v0.0.10
func ExtraValss[T, V any](next func() (T, bool), valsExtractor func(T) ([]V, error)) breakkvloop.Loop[T, V]
ExtraValss transforms a loop to the key/value loop based on applying values extractor to the elements
func ExtraValue ¶ added in v0.0.10
ExtraValue transforms a loop to the key/value loop based on applying value extractor to the elements
func ExtraValuee ¶ added in v0.0.10
func ExtraValuee[T, V any](next func() (T, bool), valExtractor func(T) (V, error)) breakkvloop.Loop[T, V]
ExtraValuee transforms a loop to the key/value loop based on applying value extractor to the elements
func Filt ¶ added in v0.0.8
Filt creates a loop that checks elements by the 'filter' function and returns successful ones.
func FiltAndConv ¶ added in v0.0.9
func FiltAndConv[From, To any](next func() (From, bool), filter func(From) (bool, error), converter func(From) (To, error)) breakloop.Loop[To]
FiltAndConv creates a loop that filters source elements and converts them
func FiltAndFlat ¶ added in v0.0.9
func FiltAndFlat[From, To any](next func() (From, bool), filter func(From) (bool, error), flattener func(From) ([]To, error)) breakloop.Loop[To]
FiltAndFlat filters source elements and extracts slices of 'To' by the 'flattener' function
func FiltFlattFilt ¶ added in v0.0.9
func FiltFlattFilt[From, To any](next func() (From, bool), filterFrom func(From) (bool, error), flattener func(From) ([]To, error), filterTo func(To) (bool, error)) breakloop.Loop[To]
FiltFlattFilt filters source elements, extracts slices of 'To' by the 'flattener' function and filters extracted elements
func FiltS ¶ added in v0.0.12
FiltS creates a loop that checks slice elements by the 'filter' function and returns successful ones.
func First ¶
First returns the first element that satisfies the condition of the 'predicate' function
func Firstt ¶ added in v0.0.12
func Firstt[T any](next func() (T, bool), predicate func(T) (bool, error)) (v T, ok bool, err error)
Firstt returns the first element that satisfies the condition of the 'predicate' function
func FlatAndFilt ¶ added in v0.0.9
func FlatAndFilt[From, To any](next func() (From, bool, error), flattener func(From) ([]To, error), filterTo func(To) (bool, error)) breakloop.Loop[To]
FlatAndFilt extracts slices of 'To' by the 'flattener' function and filters extracted elements
func Flatt ¶
func Flatt[From, To any](next func() (From, bool), flattener func(From) ([]To, error)) breakloop.Loop[To]
Flatt creates a loop that extracts slices of 'To' by the 'flattener' function from iterable elements of 'From' and flattens as one iterable collection of 'To' elements.
func FlattS ¶ added in v0.0.12
func FlattS[FS ~[]From, From, To any](elements FS, flattener func(From) ([]To, error)) breakloop.Loop[To]
FlattS creates a loop that extracts slices of 'To' by the 'flattener' function from the elements of 'From' and flattens as one iterable collection of 'To' elements.
func For ¶
For applies the 'consumer' function for the elements retrieved by the 'next' function until the consumer returns the c.Break to stop.
func ForEach ¶
ForEach applies the 'consumer' function to the elements retrieved by the 'next' function
func ForEachFiltered ¶
ForEachFiltered applies the 'consumer' function to the elements retrieved by the 'next' function that satisfy the 'predicate' function condition
func Group ¶
func Group[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V) map[K][]V
Group converts elements retrieved by the 'next' function into a new map, extracting a key for each element applying the converter 'keyExtractor'. The keyExtractor converts an element to a key. The valExtractor converts an element to a value.
func GroupByMultiple ¶
func GroupByMultiple[T any, K comparable, V any](next func() (T, bool), keysExtractor func(T) []K, valsExtractor func(T) []V) map[K][]V
GroupByMultiple converts elements retrieved by the 'next' function into a new map, extracting multiple keys, values per each element applying the 'keysExtractor' and 'valsExtractor' functions. The keysExtractor retrieves one or more keys per element. The valsExtractor retrieves one or more values per element.
func GroupByMultipleKeys ¶
func GroupByMultipleKeys[T any, K comparable, V any](next func() (T, bool), keysExtractor func(T) []K, valExtractor func(T) V) map[K][]V
GroupByMultipleKeys converts elements retrieved by the 'next' function into a new map, extracting multiple keys, one value per each element applying the 'keysExtractor' and 'valExtractor' functions. The keysExtractor retrieves one or more keys per element. The valExtractor converts an element to a value.
func GroupByMultipleValues ¶
func GroupByMultipleValues[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) K, valsExtractor func(T) []V) map[K][]V
GroupByMultipleValues converts elements retrieved by the 'next' function into a new map, extracting one key, multiple values per each element applying the 'keyExtractor' and 'valsExtractor' functions. The keyExtractor converts an element to a key. The valsExtractor retrieves one or more values per element.
func Groupp ¶ added in v0.0.10
func Groupp[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) (K, error), valExtractor func(T) (V, error)) (map[K][]V, error)
Groupp converts elements retrieved by the 'next' function into a new map, extracting a key for each element applying the converter 'keyExtractor'. The keyExtractor converts an element to a key. The valExtractor converts an element to a value.
func HasAny ¶
HasAny finds the first element that satisfies the 'predicate' function condition and returns true if successful
func KeyValue ¶ added in v0.0.10
func KeyValue[T any, K, V any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V) kvloop.Loop[K, V]
KeyValue transforms a loop to the key/value loop based on applying key, value extractors to the elements
func KeyValuee ¶ added in v0.0.10
func KeyValuee[T any, K, V any](next func() (T, bool), keyExtractor func(T) (K, error), valExtractor func(T) (V, error)) breakkvloop.Loop[K, V]
KeyValuee transforms a loop to the key/value loop based on applying key, value extractors to the elements
func KeyValues ¶ added in v0.0.10
func KeyValues[T, K, V any](next func() (T, bool), keyExtractor func(T) K, valsExtractor func(T) []V) kvloop.Loop[K, V]
KeyValues transforms a loop to the key/value loop based on applying key, values extractor to the elements
func KeyValuess ¶ added in v0.0.10
func KeyValuess[T, K, V any](next func() (T, bool), keyExtractor func(T) (K, error), valsExtractor func(T) ([]V, error)) breakkvloop.Loop[K, V]
KeyValuess transforms a loop to the key/value loop based on applying key, values extractor to the elements
func KeysValue ¶ added in v0.0.10
func KeysValue[T, K, V any](next func() (T, bool), keysExtractor func(T) []K, valExtractor func(T) V) kvloop.Loop[K, V]
KeysValue transforms a loop to the key/value loop based on applying keys, value extractor to the elements
func KeysValuee ¶ added in v0.0.10
func KeysValuee[T, K, V any](next func() (T, bool), keysExtractor func(T) ([]K, error), valExtractor func(T) (V, error)) breakkvloop.Loop[K, V]
KeysValuee transforms a loop to the key/value loop based on applying keys, value extractor to the elements
func KeysValues ¶ added in v0.0.10
func KeysValues[T, K, V any](next func() (T, bool), keysExtractor func(T) []K, valsExtractor func(T) []V) kvloop.Loop[K, V]
KeysValues transforms a loop to the key/value loop based on applying multiple keys, values extractor to the elements
func Reduce ¶
Reduce reduces the elements retrieved by the 'next' function into an one using the 'merge' function. If the 'next' function returns ok=false at the first call, the zero value of 'T' type is returned.
func ReduceOK ¶ added in v0.0.13
ReduceOK reduces the elements retrieved by the 'next' function into an one 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.12
Reducee reduces the elements 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 value of 'T' type is returned.
func ReduceeOK ¶ added in v0.0.13
func ReduceeOK[T any](next func() (T, bool), merge func(T, T) (T, error)) (result T, ok bool, err error)
ReduceeOK reduces the elements 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 SliceCap ¶
SliceCap collects the elements retrieved by the 'next' function into a new slice with predefined capacity
func ToMap ¶ added in v0.0.10
func ToMap[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V) map[K]V
ToMap collects key\value elements into a new map by iterating over the elements
func ToMapResolv ¶
func ToMapResolv[T any, K comparable, V, VR any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V, resolver func(bool, K, VR, V) VR) map[K]VR
ToMapResolv collects key\value elements into a new map by iterating over the elements with resolving of duplicated key values
func ToMapResolvOrder ¶ added in v0.0.13
func ToMapResolvOrder[TS ~[]T, T any, K comparable, V, VR any](next func() (T, bool), keyExtractor func(T) K, valExtractor func(T) V, resolver func(bool, K, VR, V) VR) ([]K, map[K]VR)
ToMapResolvOrder collects key\value elements into a new map by iterating over the elements with resolving of duplicated key values. Returns a slice with the keys ordered by the time they were added and the resolved key\value map.
func ToMapp ¶ added in v0.0.10
func ToMapp[T any, K comparable, V any](next func() (T, bool), keyExtractor func(T) (K, error), valExtractor func(T) (V, error)) (map[K]V, error)
ToMapp collects key\value elements into a new map by iterating over the elements
Types ¶
type Loop ¶ added in v0.0.12
Loop is a function that returns the next element or ok=false if there are no more elements.
func ConvertAndFilter ¶
func ConvertAndFilter[From, To any](next func() (From, bool), converter func(From) To, filter func(To) bool) Loop[To]
ConvertAndFilter additionally filters 'To' elements
func ConvertOK ¶ added in v0.0.13
func ConvertOK[From, To any](next func() (From, bool), converter func(from From) (To, bool)) Loop[To]
ConvertOK creates a loop that applies the 'converter' function to iterable elements. The converter may returns a value or ok=false to exclude the value from the loop.
func ConvertS ¶ added in v0.0.12
ConvertS creates a loop that applies the 'converter' function to the 'elements' slice.
func Crank ¶ added in v0.0.12
Crank rertieves a next element 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 FilterAndConvert ¶
func FilterAndConvert[From, To any](next func() (From, bool), filter func(From) bool, converter func(From) To) Loop[To]
FilterAndConvert creates a loop that filters source elements and converts them
func FilterAndFlat ¶ added in v0.0.9
func FilterAndFlat[From, To any](next func() (From, bool), filter func(From) bool, flattener func(From) []To) Loop[To]
FilterAndFlat filters source elements and extracts slices of 'To' by the 'flattener' function
func FilterConvertFilter ¶
func FilterConvertFilter[From, To any](next func() (From, bool), filter func(From) bool, converter func(From) To, filterTo func(To) bool) Loop[To]
FilterConvertFilter filters source, converts, and filters converted elements
func FilterFlatFilter ¶ added in v0.0.9
func FilterFlatFilter[From, To any](next func() (From, bool), filterFrom func(From) bool, flattener func(From) []To, filterTo func(To) bool) Loop[To]
FilterFlatFilter filters source elements, extracts slices of 'To' by the 'flattener' function and filters extracted elements
func FilterS ¶ added in v0.0.12
FilterS creates a loop that checks slice elements by the 'filter' function and returns successful ones.
func Flat ¶ added in v0.0.8
Flat creates a loop that extracts slices of 'To' by the 'flattener' function from iterable elements of 'From' and flattens as one iterable collection of 'To' elements.
func FlatS ¶ added in v0.0.12
FlatS creates a loop that extracts slices of 'To' by the 'flattener' function from the elements of 'From' and flattens as one iterable collection of 'To' elements.
func FlattAndFilter ¶
func FlattAndFilter[From, To any](next func() (From, bool), flattener func(From) []To, filterTo func(To) bool) Loop[To]
FlattAndFilter extracts slices of 'To' by the 'flattener' function and filters extracted elements
func NoNilPtrVal ¶ added in v0.0.10
NoNilPtrVal creates a loop that transform only not nil pointers to the values referenced referenced by those pointers. Nil pointers are ignored.
func OfIndexed ¶ added in v0.0.8
OfIndexed builds a loop by extracting elements from an indexed soruce. the len is length ot the source. the getAt retrieves an element by its index from the source.
func PtrVal ¶ added in v0.0.10
PtrVal creates a loop that transform pointers to the values referenced by those pointers. Nil pointers are transformet to zero values.
func Range ¶ added in v0.0.8
func Range[T constraints.Integer | rune](from T, toExclusive T) Loop[T]
Range creates a loop that generates integers in the range defined by from and to exclusive
func RangeClosed ¶ added in v0.0.8
func RangeClosed[T constraints.Integer | rune](from T, toInclusive T) Loop[T]
RangeClosed creates a loop that generates integers in the range defined by from and to inclusive
func Sequence ¶ added in v0.0.12
Sequence makes a sequence by applying the 'next' function to the previous step generated value.
func (Loop[T]) Accum ¶ added in v0.0.13
func (next Loop[T]) Accum(first T, merge func(T, T) T) T
Accum accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element retrieved by the 'next' function.
func (Loop[T]) Accumm ¶ added in v0.0.13
Accumm accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element retrieved by the 'next' function.
func (Loop[T]) 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[T]) Append ¶ added in v0.0.12
func (next Loop[T]) Append(out []T) []T
Append collects the elements retrieved by the 'next' function into the specified 'out' slice
func (Loop[T]) Conv ¶ added in v0.0.12
Conv creates a loop that applies the 'converter' function to iterable elements.
func (Loop[T]) Convert ¶ added in v0.0.12
Convert creates a loop that applies the 'converter' function to iterable elements.
func (Loop[T]) Crank ¶ added in v0.0.12
Crank rertieves a next element from the 'next' function, returns the function, element, successfully flag.
func (Loop[T]) Filt ¶ added in v0.0.12
Filt creates a loop that checks elements by the 'filter' function and returns successful ones.
func (Loop[T]) Filter ¶ added in v0.0.12
Filter creates a loop that checks elements by the 'filter' function and returns successful ones.
func (Loop[T]) First ¶ added in v0.0.12
First returns the first element that satisfies the condition of the 'predicate' function
func (Loop[T]) For ¶ added in v0.0.12
For applies the 'consumer' function for the elements retrieved by the 'next' function until the consumer returns the c.Break to stop.
func (Loop[T]) ForEach ¶ added in v0.0.12
func (next Loop[T]) ForEach(consumer func(T))
ForEach applies the 'consumer' function to the elements retrieved by the 'next' function
func (Loop[T]) ForEachFiltered ¶ added in v0.0.12
ForEachFiltered applies the 'consumer' function to the elements retrieved by the 'next' function that satisfy the 'predicate' function condition
func (Loop[T]) HasAny ¶ added in v0.0.12
HasAny finds the first element that satisfies the 'predicate' function condition and returns true if successful
func (Loop[T]) Reduce ¶ added in v0.0.12
func (next Loop[T]) Reduce(merge func(T, T) T) T
Reduce reduces the elements retrieved by the 'next' function into an one using the 'merge' function. If the 'next' function returns ok=false at the first call, the zero value of 'T' type is returned.
func (Loop[T]) ReduceOK ¶ added in v0.0.13
ReduceOK reduces the elements retrieved by the 'next' function into an one using the 'merge' function. Returns ok==false if the 'next' function returns ok=false at the first call (no more elements).
func (Loop[T]) Reducee ¶ added in v0.0.12
Reducee reduces the elements 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 value of 'T' type is returned.
func (Loop[T]) ReduceeOK ¶ added in v0.0.13
ReduceeOK reduces the elements retrieved by the 'next' function into an one pair using the 'merge' function.
Directories ¶
Path | Synopsis |
---|---|
Package conv provides loop converation helpers
|
Package conv provides loop converation helpers |
Package convert provides loop converation helpers
|
Package convert provides loop converation helpers |
Package filter provides aliases for loop filtering helpers
|
Package filter provides aliases for loop filtering helpers |
Package first provides short aliases for loop functions for retrieving a first element
|
Package first provides short aliases for loop functions for retrieving a first element |
Package flat provides short aliases for loop functions
|
Package flat provides short aliases for loop functions |
Package group provides short aliases for functions that are used to group elements retrieved by a loop
|
Package group provides short aliases for functions that are used to group elements retrieved by a loop |
Package range_ provides alias for the slice.Range function
|
Package range_ provides alias for the slice.Range function |
Package sum provides sum.Of alias
|
Package sum provides sum.Of alias |