go.bigb.es/auxilia
Documentation
Index
- func Reverse(inp []E) []E
- func UniqueComparableOrdered(inp []V) []V
- type ListGenerator
- type ListIterator
- func ConvertList(inp ListIterator[I], cb func(I) O) ListIterator[O]
- func FromMapKeys(inp map[K]V) ListIterator[K]
- func FromMapValues(inp map[K]V) ListIterator[V]
- func FromSlice(inp []E) ListIterator[E]
- func FromSliceWith(inp []E, cb func(E) I) ListIterator[I]
- func NewListIterator(gen ListGenerator[E], maxElements int) ListIterator[E]
- type MapGenerator
- type MapIterator
- type Tuple2
- type Tuple3
Functions
func Reverse[E any](inp []E) []E
Reverse returns a new slice with the elements of inp in reverse order. The input slice is not modified.
func UniqueComparableOrdered[V comparable](inp []V) []V
UniqueComparableOrdered deduplicates elements of inp, preserving the insertion order of the first occurrence of each value.
Types
type ListGenerator[E any] func() (E, bool)
ListGenerator produces values one at a time. It returns (value, true) for each element and (zero, false) when the sequence is exhausted.
type ListIterator[E any] interface { // Map returns an iterator that applies f to each element. Map(f func(E) E) ListIterator[E] // Filter returns an iterator that yields only elements satisfying pred. Filter(pred func(E) bool) ListIterator[E] // Sort collects all elements, sorts them with less, and returns a new iterator. Sort(less func(E, E) bool) ListIterator[E] // Skip returns an iterator that discards the first count elements. // Panics if count is negative. Skip(count int) ListIterator[E] // Limit returns an iterator that yields at most count elements. // Panics if count is negative. Limit(count int) ListIterator[E] // Count exhausts the iterator and returns the number of elements. Count() int // Apply exhausts the iterator calling f for each element and returns the count. Apply(f func(E)) int // Collect collects all remaining elements into a slice. Collect() []E // MapIndex returns an iterator that applies f with the 0-based index to each element. MapIndex(f func(int, E) E) ListIterator[E] // FilterIndex returns an iterator that yields only elements where pred(index, elem) is true. FilterIndex(pred func(int, E) bool) ListIterator[E] // Unique returns an iterator that deduplicates elements using the string key returned by fn. Unique(fn func(E) string) ListIterator[E] // ApplyIndex exhausts the iterator calling f with the 0-based index for each element. ApplyIndex(f func(int, E)) // Materialize materializes the iterator and returns a new iterator over the result. Materialize() ListIterator[E] }
ListIterator is a lazy, pull-based iterator over a sequence of elements. All intermediate operations (Map, Filter, Sort, Skip, Limit) return a new iterator; terminal operations (Count, Apply, Collect) consume it.
func ConvertList[I any, O any](inp ListIterator[I], cb func(I) O) ListIterator[O]
ConvertList transforms a ListIterator of type I into a ListIterator of type O by applying cb to each element.
func FromMapKeys[K comparable, V any](inp map[K]V) ListIterator[K]
FromMapKeys creates a ListIterator over the keys of a map.
func FromMapValues[K comparable, V any](inp map[K]V) ListIterator[V]
FromMapValues creates a ListIterator over the values of a map.
func FromSlice[E any](inp []E) ListIterator[E]
FromSlice creates a ListIterator that yields the elements of inp in order.
func FromSliceWith[E any, I any](inp []E, cb func(E) I) ListIterator[I]
FromSliceWith creates a ListIterator that maps each element of inp through cb.
func NewListIterator[E any](gen ListGenerator[E], maxElements int) ListIterator[E]
NewListIterator creates a ListIterator backed by gen. maxElements is a hint for the expected upper bound of elements (used for pre-allocation); pass -1 if unknown.
type MapGenerator[K comparable, V any] func() (K, V, bool)
MapGenerator produces key-value pairs one at a time. It returns (key, value, true) for each pair and (zeroK, zeroV, false) when the sequence is exhausted.
type MapIterator[K comparable, V any] interface { // MapValues returns an iterator that transforms values by applying f, keeping keys unchanged. MapValues(f func(K, V) V) MapIterator[K, V] // MapEntries returns an iterator that transforms both keys and values by applying f. MapEntries(f func(K, V) (K, V)) MapIterator[K, V] // Filter returns an iterator that yields only pairs satisfying pred. Filter(pred func(K, V) bool) MapIterator[K, V] // Unique returns an iterator that deduplicates pairs by the string key returned by fn. Unique(fn func(K, V) string) MapIterator[K, V] // MapValuesIndex returns an iterator that transforms values by applying f with a 0-based index. MapValuesIndex(f func(int, K, V) V) MapIterator[K, V] // MapEntriesIndex returns an iterator that transforms both keys and values by applying f with a 0-based index. MapEntriesIndex(f func(int, K, V) (K, V)) MapIterator[K, V] // FilterIndex returns an iterator that yields only pairs satisfying pred, which receives a 0-based index. FilterIndex(pred func(int, K, V) bool) MapIterator[K, V] // Apply exhausts the iterator, calling f for each key-value pair. Apply(f func(K, V)) // Collect collects all remaining pairs into a map. Collect() map[K]V // Materialize materializes all pairs into a map and returns a new iterator over it. // If less is non-nil the keys are visited in sorted order; otherwise the order is unspecified. Materialize(less func(K, K) bool) MapIterator[K, V] // Skip returns an iterator that discards the first count pairs. // Panics if count is negative. Skip(count int) MapIterator[K, V] // Limit returns an iterator that yields at most count elements. // Panics if count is negative. Limit(count int) MapIterator[K, V] // Keys returns a ListIterator that yields the keys. Keys() ListIterator[K] // Values returns a ListIterator that yields the values. Values() ListIterator[V] }
MapIterator is a lazy, pull-based iterator over key-value pairs. All intermediate operations (MapValues, MapEntries, Filter, Skip, Limit, etc.) return a new iterator; terminal operations (Apply, Collect) consume it.
func FromMap[K comparable, V any](inp map[K]V, less func(K, K) bool) MapIterator[K, V]
FromMap creates a MapIterator that yields the entries of inp. If less is non-nil the keys are visited in sorted order; otherwise the iteration order is unspecified (uses reflect.MapRange).
func NewMapIterator[K comparable, V any](gen MapGenerator[K, V], maxElements int) MapIterator[K, V]
NewMapIterator creates a MapIterator backed by gen. maxElements is a hint for the expected upper bound of pairs (used for pre-allocation); pass -1 if unknown.
type Tuple2[T1 any, T2 any] struct { // contains filtered or unexported fields }
Tuple2 is a generic pair of values.
NewTuple2 creates a Tuple2 holding first and second.
func (t *Tuple2[T1, T2]) First() T1
First returns the first element of the pair.
func (t *Tuple2[T1, T2]) Second() T2
Second returns the second element of the pair.
type Tuple3[T1 any, T2 any, T3 any] struct { // contains filtered or unexported fields }
Tuple3 is a generic triple of values.
NewTuple3 creates a Tuple3 holding first, second, and third.
func (t *Tuple3[T1, T2, T3]) First() T1
First returns the first element of the triple.
func (t *Tuple3[T1, T2, T3]) Second() T2
Second returns the second element of the triple.
func (t *Tuple3[T1, T2, T3]) Third() T3
Third returns the third element of the triple.
Package collect provides generic collection types, lazy iterators, and slice helpers.