Documentation
¶
Index ¶
- func FindPosition[T Number](p T) func(T) bool
- func Fold[T any, R any](i It[T], initial R, accumulator func(R, T) R) R
- func Max[T Ordered](a, b T) bool
- func Min[T Ordered](a, b T) bool
- func OrderAsc[T Ordered](a, b T) int
- func OrderDesc[T Ordered](a, b T) int
- func OrderStructAsc[T OrderedStruct[T]](a, b T) bool
- func OrderStructDesc[T OrderedStruct[T]](a, b T) bool
- func RFold[T any, R any](i It[T], initial R, accumulator func(T, R) R) R
- func Sum[T Number](a, b T) T
- type Entry
- type It
- func ChainAll[V any](its ...It[V]) It[V]
- func CollectIt2ToIt[K comparable, V, R any](i It2[K, V], mapper func(K, V) R) It[R]
- func Distinct[T comparable](i It[T]) It[T]
- func FlatMap[T any, U any](i It[T], transform func(T) It[U]) It[U]
- func Flatten[V any](nested It[iter.Seq[V]]) It[V]
- func From[T any](args ...T) It[T]
- func FromSlice[T any](slice []T) It[T]
- func Map[T any, U any](i It[T], transform func(T) U) It[U]
- func Zip[T, R any](i1 It[T], i2 It[R]) ...
- func (it It[T]) All(predicate func(T) bool) bool
- func (it It[T]) Any(predicate func(T) bool) bool
- func (it It[T]) AsSeq() iter.Seq[T]
- func (it It[T]) Chain(i2 It[T]) It[T]
- func (it It[T]) Collect() []T
- func (it It[T]) Compare(cmp func(T, T) bool) nilo.Option[T]
- func (it It[T]) Count() int
- func (it It[T]) Enumerate() iter.Seq2[int, T]
- func (it It[T]) Filter(predicate func(T) bool) It[T]
- func (it It[T]) FilterMap(mapper func(T) nilo.Option[T]) It[T]
- func (it It[T]) FilterMapToInt(mapper func(T) nilo.Option[int]) It[int]
- func (it It[T]) FilterMapToString(mapper func(T) nilo.Option[string]) It[string]
- func (it It[T]) Find(predicate func(T) bool) nilo.Option[T]
- func (it It[T]) First() nilo.Option[T]
- func (it It[T]) FlatMap(mapper func(T) It[T]) It[T]
- func (it It[T]) FlatMapToInt(mapper func(T) It[int]) It[int]
- func (it It[T]) FlatMapToString(mapper func(T) It[string]) It[string]
- func (it It[T]) Fold(initValue T, acc func(T, T) T) T
- func (it It[T]) ForEach(consumer func(T))
- func (it It[T]) ForEachIdx(consumer func(int, T))
- func (it It[T]) Inspect(inspector func(T)) It[T]
- func (it It[T]) Last() nilo.Option[T]
- func (it It[T]) Map(mapper func(T) T) It[T]
- func (it It[T]) MapToInt(mapper func(T) int) It[int]
- func (it It[T]) MapToString(mapper func(T) string) It[string]
- func (it It[T]) None(predicate func(T) bool) bool
- func (it It[T]) Nth(n int) nilo.Option[T]
- func (it It[T]) Partition(politer func(T) bool) (It[T], It[T])
- func (it It[T]) Position(predicate func(T) bool) nilo.Option[int]
- func (it It[T]) RFold(initValue T, acc func(T, T) T) T
- func (it It[T]) RPosition(predicate func(T) bool) nilo.Option[int]
- func (it It[T]) Reverse() It[T]
- func (it It[T]) Skip(n int) It[T]
- func (it It[T]) SkipWhile(predicate func(T) bool) It[T]
- func (it It[T]) SortBy(cmp func(T, T) int) It[T]
- func (it It[T]) Take(n int) It[T]
- func (it It[T]) TakeWhile(predicate func(T) bool) It[T]
- type It2
- func CollectItToIt2[T, K comparable, V any](i It[T], keyFunc func(T) K, valueFunc func(T) V) It2[K, V]
- func FromMap[K comparable, V any](m map[K]V) It2[K, V]
- func GroupBy[K comparable, V any](i It[V], classifier func(V) K) It2[K, It[V]]
- func GroupByCounting[K comparable, V any](i It[V], classifier func(V) K) It2[K, int]
- func (it It2[K, V]) All(predicate func(K, V) bool) bool
- func (it It2[K, V]) Any(predicate func(K, V) bool) bool
- func (it It2[K, V]) Collect() map[K]V
- func (it It2[K, V]) Compare(cmp func(K, K) bool) nilo.Option[Entry[K, V]]
- func (it It2[K, V]) Count() int
- func (it It2[K, V]) Filter(predicate func(K, V) bool) It2[K, V]
- func (it It2[K, V]) ForEach(consumer func(K, V))
- func (it It2[K, V]) Inspect(consumer func(K, V)) It2[K, V]
- func (it It2[K, V]) Keys() It[K]
- func (it It2[K, V]) Map(mapper func(K, V) (K, V)) It2[K, V]
- func (it It2[K, V]) MapToInt(mapper func(K, V) (K, int)) It2[K, int]
- func (it It2[K, V]) MapToString(mapper func(K, V) (K, string)) It2[K, string]
- func (it It2[K, V]) None(predicate func(K, V) bool) bool
- func (it It2[K, V]) SortBy(cmp func(K, K) bool) It2[K, V]
- func (it It2[K, V]) Take(n int) It2[K, V]
- func (it It2[K, V]) Values() It[V]
- type Number
- type Ordered
- type OrderedStruct
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindPosition ¶
FindPosition returns a function that checks if a given value x is equal to the specified position p. The returned function takes a single argument of type T and returns true if it matches p.
func Fold ¶
Fold reduces the iterator to a single value by applying an accumulator function, starting with an initial value and processing from left to right.
func Max ¶
Max returns true if the first argument a is less than the second argument b. It is intended to be used with types that implement the Ordered interface, which allows for comparison operations.
func Min ¶
Min returns true if the first argument a is greater than the second argument b. It is intended to be used with types that implement the Ordered interface, which allows for comparison operations.
func OrderAsc ¶
OrderAsc compares two Ordered values in ascending order. It returns -1 if the first value is greater than the second.
func OrderDesc ¶
OrderDesc compares two Ordered values in descending order. It returns -1 if the first value is less than the second.
func OrderStructAsc ¶
func OrderStructAsc[T OrderedStruct[T]](a, b T) bool
OrderStructAsc compares two OrderedStructs in ascending order. It returns true if the first struct is greater than the second.
func OrderStructDesc ¶
func OrderStructDesc[T OrderedStruct[T]](a, b T) bool
OrderStructDesc compares two OrderedStructs in descending order. It returns true if the first struct is less than the second.
Types ¶
type Entry ¶
type Entry[K comparable, V any] struct { Key K Value V }
Entry is a generic struct that holds a key-value pair.
type It ¶
It is a wrapper around iter.Seq[T] that provides a fluent API for functional-style iterator transformations.
func ChainAll ¶
ChainAll concatenates multiple iterators into a single iterator that yields all elements from the first, then the second, and so on.
func CollectIt2ToIt ¶
func CollectIt2ToIt[K comparable, V, R any](i It2[K, V], mapper func(K, V) R) It[R]
CollectIt2ToIt transforms a two-value iterator (it2) into a single-value iterator by applying a mapper function to each key-value pair.
func Distinct ¶
func Distinct[T comparable](i It[T]) It[T]
Distinct returns an iterator that yields only unique elements from the input iterator. It uses a map to track seen elements, which requires O(N) memory.
func FlatMap ¶
FlatMap returns an iterator that applies a transform function to each element, where the transform returns another iterator. It then flattens the resulting iterators into a single sequence.
func Flatten ¶
Flatten takes an iterator of sequences and returns a single iterator yielding all elements from the nested sequences in order.
func Map ¶
Map returns an iterator that applies the transform function to each element of the input iterator and yields the results.
func Zip ¶
Zip combines two iterators into a single iterator of structs containing elements from both. It stops as soon as either input iterator is exhausted.
func (It[T]) All ¶
All returns true if every element satisfies the predicate. It short-circuits on the first false result.
func (It[T]) Any ¶
Any returns true if at least one element satisfies the predicate. It short-circuits on the first true result.
func (It[T]) Collect ¶
func (it It[T]) Collect() []T
Collect consumes the iterator and returns a slice of all elements.
func (It[T]) Compare ¶
Compare finds the "best" element based on the provided comparison function (e.g., to find Min or Max). Note: Use helper functions like steams.Min, steams.Max
func (It[T]) Count ¶
Count consumes the iterator and returns the total number of elements. Note: This collects the iterator into memory to determine length.
func (It[T]) Filter ¶
Filter returns an iterator containing only elements that satisfy the predicate.
func (It[T]) FilterMap ¶
FilterMap applies a mapper that returns an Option. Only "Value" options are yielded, effectively filtering and transforming in one step.
func (It[T]) FilterMapToInt ¶
FilterMapToInt is a FilterMap variant that yields a sequence of ints.
func (It[T]) FilterMapToString ¶
FilterMapToString is a FilterMap variant that yields a sequence of strings.
func (It[T]) First ¶
First returns the first element as an Option, or an empty Option if the iterator is empty.
func (It[T]) FlatMap ¶
FlatMap applies a mapper that returns an iterator for each element, then flattens all resulting iterators into a single sequence.
func (It[T]) FlatMapToInt ¶
FlatMapToInt is a FlatMap variant resulting in a sequence of ints.
func (It[T]) FlatMapToString ¶
FlatMapToString is a FlatMap variant resulting in a sequence of strings.
func (It[T]) Fold ¶
func (it It[T]) Fold(initValue T, acc func(T, T) T) T
Fold reduces the sequence to a single value using an accumulator, starting with initValue and processing from left to right.
func (It[T]) ForEach ¶
func (it It[T]) ForEach(consumer func(T))
ForEach executes the consumer function for every element in the iterator. This is a terminal operation.
func (It[T]) ForEachIdx ¶
ForEachIdx executes the consumer function for every element, providing the current 0-based index. This is a terminal operation.
func (It[T]) Inspect ¶
Inspect applies a function to each element without modifying the sequence. Useful for debugging or side effects during iteration.
func (It[T]) Last ¶
Last returns the final element of the iterator. Note: This collects the entire sequence into memory first.
func (It[T]) MapToString ¶
MapToString applies a mapper that transforms each element into a string.
func (It[T]) Partition ¶
Partition splits the iterator into two collections: those that satisfy the predicate and those that do not.
func (It[T]) RFold ¶
func (it It[T]) RFold(initValue T, acc func(T, T) T) T
RFold reduces the sequence to a single value processing from right to left. Note: This collects the entire sequence into memory first.
func (It[T]) RPosition ¶
RPosition returns the index of the last element satisfying the predicate. Note: This collects the entire sequence into memory first.
func (It[T]) Reverse ¶
Reverse returns an iterator that yields elements in reverse order. Note: This collects the entire sequence into memory first.
func (It[T]) SkipWhile ¶
SkipWhile discards elements until the predicate returns false, then yields all remaining elements.
func (It[T]) SortBy ¶
SortBy returns an iterator yielding elements in the order defined by the comparison function. Note: This collects and sorts the entire sequence in memory.
type It2 ¶
type It2[K comparable, V any] iter.Seq2[K, V]
It2 is a wrapper around iter.Seq2[K, V] that provides a fluent API for functional-style transformations on key-value sequences.
func CollectItToIt2 ¶
func CollectItToIt2[T, K comparable, V any](i It[T], keyFunc func(T) K, valueFunc func(T) V) It2[K, V]
CollectItToIt2 transforms a single-value iterator into a two-value iterator (it2) by applying key and value mapping functions to each element.
func FromMap ¶
func FromMap[K comparable, V any](m map[K]V) It2[K, V]
FromMap creates an It2 iterator from a standard Go map.
func GroupBy ¶
func GroupBy[K comparable, V any](i It[V], classifier func(V) K) It2[K, It[V]]
GroupBy organizes elements of the input iterator into groups based on a classifier function. It returns a sequence of keys and their corresponding iterators.
func GroupByCounting ¶
func GroupByCounting[K comparable, V any](i It[V], classifier func(V) K) It2[K, int]
GroupByCounting counts the occurrences of keys generated by the classifier function and returns an iterator of key-count pairs.
func (It2[K, V]) Any ¶
Any returns true if at least one element in the iterator satisfies the predicate.
func (It2[K, V]) Collect ¶
func (it It2[K, V]) Collect() map[K]V
Collect consumes the iterator and returns a map of all key-value pairs.
func (It2[K, V]) Compare ¶
Compare returns the "best" Entry based on the comparison function. If the iterator is empty, it returns a Nil option.
func (It2[K, V]) Count ¶
Count consumes the iterator and returns the total number of pairs. Note: This implementation collects the iterator into a map to determine length.
func (It2[K, V]) Filter ¶
Filter returns an It2 iterator containing only the pairs that satisfy the predicate.
func (It2[K, V]) ForEach ¶
func (it It2[K, V]) ForEach(consumer func(K, V))
ForEach executes the consumer function for every key-value pair in the sequence. This is a terminal operation.
func (It2[K, V]) Inspect ¶
Inspect applies a function to each pair without modifying the sequence. Note: In its current implementation, this consumes the iterator immediately.
func (It2[K, V]) Map ¶
Map returns an It2 iterator that applies a transformation function to each key-value pair.
func (It2[K, V]) MapToInt ¶
MapToInt applies a mapper that transforms the value into an int while keeping or transforming the key.
func (It2[K, V]) MapToString ¶
MapToString applies a mapper that transforms the value into a string while keeping or transforming the key.
func (It2[K, V]) SortBy ¶
SortBy returns an iterator that yields pairs sorted based on the keys according to the provided comparison function. Note: This collects the entire sequence into memory before sorting.
type Number ¶
type Number interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64
}
Number is a type constraint that includes all sumable types. It allows for summing various numeric types.
type Ordered ¶
Ordered is a type constraint that includes all ordered types. It allows for comparison of various numeric types and strings.
type OrderedStruct ¶
OrderedStruct is an interface for structs that can be compared. It requires the implementation of a Compare method that returns an integer. The method should return a negative value if the receiver is less than the other, zero if they are equal, and a positive value if the receiver is greater.