github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/break/kv/loop/loop.go (about)

     1  package loop
     2  
     3  // Loop is a function that returns the next key, value or false if there are no more elements.
     4  type Loop[K, V any] func() (K, V, bool, error)
     5  
     6  // Track applies the 'consumer' function to position/element pairs retrieved by the 'next' function until the consumer returns the c.Break to stop.
     7  func (next Loop[K, V]) Track(consumer func(K, V) error) error {
     8  	return Track(next, consumer)
     9  }
    10  
    11  // First returns the first element that satisfies the condition of the 'predicate' function
    12  func (next Loop[K, V]) First(predicate func(K, V) bool) (K, V, bool, error) {
    13  	return First(next, predicate)
    14  }
    15  
    16  // Reduce reduces the elements retrieved by the 'next' function into an one using the 'merge' function.
    17  func (next Loop[K, V]) Reduce(merge func(K, K, V, V) (K, V)) (K, V, error) {
    18  	return Reduce(next, merge)
    19  }
    20  
    21  // Reducee reduces the elements retrieved by the 'next' function into an one using the 'merge' function.
    22  func (next Loop[K, V]) Reducee(merge func(K, K, V, V) (K, V, error)) (K, V, error) {
    23  	return Reducee(next, merge)
    24  }
    25  
    26  // HasAny finds the first element that satisfies the 'predicate' function condition and returns true if successful
    27  func (next Loop[K, V]) HasAny(predicate func(K, V) bool) (bool, error) {
    28  	return HasAny(next, predicate)
    29  }
    30  
    31  // Filt creates a loop that checks elements by the 'filter' function and returns successful ones.
    32  func (next Loop[K, V]) Filt(filter func(K, V) (bool, error)) Loop[K, V] {
    33  	return Filt(next, filter)
    34  }
    35  
    36  // Filter creates a loop that checks elements by the 'filter' function and returns successful ones.
    37  func (next Loop[K, V]) Filter(filter func(K, V) bool) Loop[K, V] {
    38  	return Filter(next, filter)
    39  }
    40  
    41  // Crank rertieves next key\value elements from the 'next' function, returns the function, element, successfully flag.
    42  func (next Loop[K, V]) Crank() (Loop[K, V], K, V, bool, error) {
    43  	return Crank(next)
    44  }