Documentation
¶
Index ¶
- func Aggregate[T any, R any](it iter.Seq[T], initial R, accumulator func(R, T) R) R
- func All[T any](it iter.Seq[T], predicate func(T) bool) bool
- func Any[T any](it iter.Seq[T], predicate func(T) bool) bool
- func Append[T any](it iter.Seq[T], value T) iter.Seq[T]
- func Average[T constraints.Integer | constraints.Float](it iter.Seq[T]) T
- func Cast[T, R any](it iter.Seq[T]) iter.Seq[R]
- func Chunk[T any](source iter.Seq[T], chunkSize int) iter.Seq[iter.Seq[T]]
- func Concat[T any](its ...iter.Seq[T]) iter.Seq[T]
- func Contains[T comparable](it iter.Seq[T], value T) bool
- func Count[T any](it iter.Seq[T]) int
- func CountWhere[T any](it iter.Seq[T], predicate func(T) bool) int
- func DefaultIfEmpty[T any](it iter.Seq[T], defaultValue T) iter.Seq[T]
- func Distinct[T comparable](it iter.Seq[T]) iter.Seq[T]
- func DistinctBy[T any, K comparable](it iter.Seq[T], keySelector func(T) K) iter.Seq[T]
- func ElementAt[T any](it iter.Seq[T], index int) T
- func ElementAtOrDefault[T any](it iter.Seq[T], index int) T
- func Empty[T any]() iter.Seq[T]
- func Except[T comparable](first, second iter.Seq[T]) iter.Seq[T]
- func First[T any](it iter.Seq[T]) T
- func FirstOrDefault[T any](it iter.Seq[T]) T
- func FirstWhere[T any](it iter.Seq[T], predicate func(T) bool) T
- func FirstWhereOrDefault[T any](it iter.Seq[T], predicate func(T) bool) T
- func ForEach[T any](it iter.Seq[T], yield func(T) bool)
- func GroupBy[T any, K comparable](it iter.Seq[T], keySelector func(T) K) iter.Seq[Grouping[K, T]]
- func GroupByWithValue[T any, K comparable, V any](it iter.Seq[T], keySelector func(T) K, valueSelector func(T) V) iter.Seq[Grouping[K, V]]
- func Intersect[T comparable](first, second iter.Seq[T]) iter.Seq[T]
- func Last[T any](it iter.Seq[T]) T
- func LastOrDefault[T any](it iter.Seq[T]) T
- func LastWhere[T any](it iter.Seq[T], predicate func(T) bool) T
- func LastWhereOrDefault[T any](it iter.Seq[T], predicate func(T) bool) T
- func Max[T constraints.Ordered](it iter.Seq[T]) T
- func MaxBy[T any, V constraints.Ordered](it iter.Seq[T], selector func(T) V) T
- func Min[T constraints.Ordered](it iter.Seq[T]) T
- func MinBy[T any, V constraints.Ordered](it iter.Seq[T], selector func(T) V) T
- func OfType[T, R any](it iter.Seq[T]) iter.Seq[R]
- func Order[T any](it iter.Seq[T], spec OrderSpec[T]) iter.Seq[T]
- func OrderBy[T any](it iter.Seq[T], less func(a, b T) bool) iter.Seq[T]
- func Prepend[T any](it iter.Seq[T], value T) iter.Seq[T]
- func Range(start, count int) iter.Seq[int]
- func Repeat[T any](value T, count int) iter.Seq[T]
- func Select[T, R any](it iter.Seq[T], selector func(T) R) iter.Seq[R]
- func SelectMany[T, R any](it iter.Seq[T], selector func(T) iter.Seq[R]) iter.Seq[R]
- func SequenceEqual[T comparable](first, second iter.Seq[T]) bool
- func Single[T any](it iter.Seq[T]) T
- func SingleOrDefault[T any](it iter.Seq[T]) T
- func Skip[T any](it iter.Seq[T], count int) iter.Seq[T]
- func SkipWhile[T any](it iter.Seq[T], predicate func(T) bool) iter.Seq[T]
- func Sum[T constraints.Integer | constraints.Float](it iter.Seq[T]) T
- func Take[T any](it iter.Seq[T], count int) iter.Seq[T]
- func TakeWhile[T any](it iter.Seq[T], predicate func(T) bool) iter.Seq[T]
- func ToSlice[T any](it iter.Seq[T]) []T
- func TryEach[T any](it iter.Seq[T], yield func(T) bool) (err error)
- func Union[T comparable](first, second iter.Seq[T]) iter.Seq[T]
- func Where[T any](it iter.Seq[T], predicate func(T) bool) iter.Seq[T]
- func Zip[T, U, R any](first iter.Seq[T], second iter.Seq[U], resultSelector func(T, U) R) iter.Seq[R]
- type Grouping
- type OrderSpec
- func By[T any, K any](keySelector func(T) K, less func(K, K) bool) OrderSpec[T]
- func ByDescending[T any, K any](keySelector func(T) K, less func(K, K) bool) OrderSpec[T]
- func Then[T any, K any](spec OrderSpec[T], keySelector func(T) K, less func(K, K) bool) OrderSpec[T]
- func ThenDescending[T any, K any](spec OrderSpec[T], keySelector func(T) K, less func(K, K) bool) OrderSpec[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Average ¶
func Average[T constraints.Integer | constraints.Float](it iter.Seq[T]) T
func Chunk ¶
There is no way to chunk a push iter. A poor way is to create a goproc to redirect the iter to push to a chan, then read the chan chunk by chunk in current goproc. iter.Pull makes it better by introducing a new lightweight coroutine (a stack-less state machine without preemption etc.)
func Contains ¶
func Contains[T comparable](it iter.Seq[T], value T) bool
Contains checks if the sequence contains the specified value
func CountWhere ¶
CountWhere returns the number of elements that satisfy the predicate
func DefaultIfEmpty ¶
DefaultIfEmpty returns the sequence or a sequence with a single default value if empty
func DistinctBy ¶
DistinctBy returns distinct elements based on a key selector function
func ElementAtOrDefault ¶
ElementAtOrDefault returns the element at the specified index or zero value
func Except ¶
func Except[T comparable](first, second iter.Seq[T]) iter.Seq[T]
Except returns the set difference of two sequences
func FirstOrDefault ¶
FirstOrDefault returns the first element or zero value if empty
func FirstWhere ¶
FirstWhere returns the first element that satisfies the predicate
func FirstWhereOrDefault ¶
FirstWhereOrDefault returns the first element that satisfies the predicate or zero value
func GroupByWithValue ¶
func GroupByWithValue[T any, K comparable, V any](it iter.Seq[T], keySelector func(T) K, valueSelector func(T) V) iter.Seq[Grouping[K, V]]
GroupByWithValue groups elements by a key selector and transforms values. It has to COPY ALL items.
func Intersect ¶
func Intersect[T comparable](first, second iter.Seq[T]) iter.Seq[T]
Intersect returns the set intersection of two sequences
func LastOrDefault ¶
LastOrDefault returns the last element or zero value if empty
func LastWhereOrDefault ¶
LastWhereOrDefault returns the last element that satisfies the predicate or zero value
func OfType ¶
OfType filters elements to those of a specific type (using type assertion) This is a simplified version since Go doesn't have runtime type information like .NET
func Order ¶
Order sorts the sequence using the specified multi-level ordering criteria. The OrderSpec parameter should be built using By() and Then() functions.
This function materializes the entire sequence into a slice, sorts it using Go's stable sort, and then yields the sorted elements.
Example:
sorted := Order(seq, By(ageSelector, intLess).Then(nameSelector, stringLess))
Multi-level example:
sorted := Order(seq,
Then(
ThenDescending(
By(gradeSelector, intLess), // Primary: grade ascending
scoreSelector, intLess), // Secondary: score descending
nameSelector, stringLess)) // Tertiary: name ascending
func OrderBy ¶
OrderBy sorts the sequence using a single less function, similar to sort.SliceStable. Example:
OrderBy(seq, func(a, b Person) bool {
if a.Age != b.Age { return a.Age < b.Age }
return a.Name < b.Name
})
func SelectMany ¶
SelectMany flattens sequences
func SequenceEqual ¶
func SequenceEqual[T comparable](first, second iter.Seq[T]) bool
SequenceEqual determines whether two sequences are equal
func SingleOrDefault ¶
SingleOrDefault returns the only element or zero value
func Sum ¶
func Sum[T constraints.Integer | constraints.Float](it iter.Seq[T]) T
func Union ¶
func Union[T comparable](first, second iter.Seq[T]) iter.Seq[T]
Union returns the set union of two sequences (removes duplicates)
Types ¶
type Grouping ¶
type Grouping[K comparable, V any] struct { Key K Values iter.Seq[V] }
GroupBy groups elements by a key selector
type OrderSpec ¶
type OrderSpec[T any] struct { // contains filtered or unexported fields }
OrderSpec represents a multi-level ordering specification that can be built using a fluent API for complex sorting scenarios.
Example usage:
Order(seq, By(keyFunc, lessFunc).Then(keyFunc2, lessFunc2).ThenDescending(keyFunc3, lessFunc3))
Or step by step:
spec := By(keyFunc, lessFunc) spec = Then(spec, keyFunc2, lessFunc2) spec = ThenDescending(spec, keyFunc3, lessFunc3) result := Order(seq, spec)
func By ¶
By creates a new OrderSpec with the first ordering criteria in ascending order. This is the starting point for building multi-level sort specifications.
Example:
spec := By(func(p Person) int { return p.Age }, func(a, b int) bool { return a < b })
func ByDescending ¶
ByDescending creates a new OrderSpec with the first ordering criteria in descending order.
Example:
spec := ByDescending(func(p Person) int { return p.Age }, func(a, b int) bool { return a < b })
func Then ¶
func Then[T any, K any](spec OrderSpec[T], keySelector func(T) K, less func(K, K) bool) OrderSpec[T]
Then adds a secondary ordering criteria in ascending order. This allows chaining multiple sort criteria where subsequent criteria are used to break ties from previous criteria.
Example:
spec = Then(spec, func(p Person) string { return p.Name }, func(a, b string) bool { return a < b })
func ThenDescending ¶
func ThenDescending[T any, K any](spec OrderSpec[T], keySelector func(T) K, less func(K, K) bool) OrderSpec[T]
ThenDescending adds a secondary ordering criteria in descending order.
Example:
spec = ThenDescending(spec, func(p Person) int { return p.Score }, func(a, b int) bool { return a < b })