Documentation
¶
Index ¶
- func Identify[V any]() func(v V) V
- type AvgContainer
- type BaseCollector
- type Collector
- func NewAvgCollector[T any, R constraints.Integer | constraints.Float](mapper func(T) R) Collector[T, *AvgContainer[R], R]
- func NewAvgCollectorInParallel[T any, R constraints.Integer | constraints.Float](mapper func(T) R) Collector[T, *AvgContainer[R], R]
- func NewCountCollector[T any]() Collector[T, *CountContainer, int]
- func NewCountCollectorInParallel[T any]() Collector[T, *CountContainerInParallel, int]
- func NewGroupByCollector[T any, K comparable](keyMapper func(T) K) Collector[T, map[K][]T, map[K][]T]
- func NewGroupByCollectorWithValueMapper[T any, K comparable, V any](keyMapper func(T) K, valueMapper func(T) (v V)) Collector[T, map[K][]V, map[K][]V]
- func NewJoiningCollector[T any](separator string) Collector[T, *strings.Builder, string]
- func NewJoiningCollectorInParallel[T any](separator string) Collector[T, *strings.Builder, string]
- func NewMaxCollector[T any, R constraints.Ordered](mapper func(T) R) Collector[T, *MaxContainer[R], R]
- func NewMaxCollectorInParallel[T any, R constraints.Ordered](mapper func(T) R) Collector[T, *MaxContainer[R], R]
- func NewMinCollector[T any, R constraints.Ordered](mapper func(T) R) Collector[T, *MinContainer[R], R]
- func NewMinCollectorInParallel[T any, R constraints.Ordered](mapper func(T) R) Collector[T, *MinContainer[R], R]
- func NewSumCollector[T any, R constraints.Integer | constraints.Float](mapper func(T) R) Collector[T, *SumContainer[R], R]
- func NewSumCollectorInParallel[T any, R constraints.Integer | constraints.Float](mapper func(T) R) Collector[T, *SumContainer[R], R]
- func NewToMapCollector[T any, K comparable](size int, keyMapper func(T) K) Collector[T, map[K]T, map[K]T]
- func NewToMapCollectorWithDuplicateHandler[T any, K comparable, V any](size int, keyMapper func(T) K, valueMapper func(T) V, ...) Collector[T, map[K]V, map[K]V]
- func NewToMapWithIgnoreDuplicateCollector[T any, K comparable](size int, keyMapper func(T) K) Collector[T, map[K]T, map[K]T]
- func NewToSliceCollector[T any](size int) Collector[T, *SliceContainer[T], []T]
- func NewToSliceCollectorInParallel[T any](size int) Collector[T, *SliceContainer[T], []T]
- type CountContainer
- type CountContainerInParallel
- type MaxContainer
- type MinContainer
- type SliceContainer
- type SumContainer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AvgContainer ¶
type AvgContainer[R constraints.Integer | constraints.Float] struct { // contains filtered or unexported fields }
type BaseCollector ¶
func NewBaseCollector ¶
func NewBaseCollector[T any, A any, R any]( supplier func() A, accumulator func(container A, item T), finisher func(container A) R, ) *BaseCollector[T, A, R]
func (*BaseCollector[T, A, R]) Accumulator ¶
func (bc *BaseCollector[T, A, R]) Accumulator() func(container A, item T)
func (*BaseCollector[T, A, R]) Finisher ¶
func (bc *BaseCollector[T, A, R]) Finisher() func(container A) R
func (*BaseCollector[T, A, R]) Supplier ¶
func (bc *BaseCollector[T, A, R]) Supplier() func() A
type Collector ¶
type Collector[T any, A any, R any] interface { // Supplier returns a function that returns a new, mutable result container. Supplier() func() A // Accumulator returns a function that folds a value into a mutable result container. Accumulator() func(container A, item T) // Finisher returns a function that transforms the final accumulator into the result of the reduction. Finisher() func(container A) R }
Collector is a mutable reduction operation that accumulates input elements into a mutable result container, optionally transforming the accumulated result into a final representation after all input elements have been processed. Reduction operations can be performed either sequentially or in parallel.
func NewAvgCollector ¶
func NewAvgCollector[T any, R constraints.Integer | constraints.Float]( mapper func(T) R) Collector[T, *AvgContainer[R], R]
NewAvgCollector returns a Collector that computes the average of the elements of the stream.
Note: The returned Collector is not routine-safe.
func NewAvgCollectorInParallel ¶
func NewAvgCollectorInParallel[T any, R constraints.Integer | constraints.Float]( mapper func(T) R) Collector[T, *AvgContainer[R], R]
NewAvgCollectorInParallel returns a Collector that computes the average of the elements of the stream.
Note: The returned Collector is routine-safe.
func NewCountCollector ¶
func NewCountCollector[T any]() Collector[T, *CountContainer, int]
NewCountCollector returns a Collector that computes the counterimum of the elements of the stream.
Note: The returned Collector is not routine-safe.
func NewCountCollectorInParallel ¶
func NewCountCollectorInParallel[T any]() Collector[T, *CountContainerInParallel, int]
NewCountCollectorInParallel returns a Collector that computes the counterimum of the elements of the stream.
Note: The returned Collector is routine-safe.
func NewGroupByCollector ¶
func NewGroupByCollector[T any, K comparable]( keyMapper func(T) K, ) Collector[T, map[K][]T, map[K][]T]
NewGroupByCollector returns a collector that accumulates the input elements into a map whose keys are the result of applying the provided mapping function to the input elements, and values are the input elements.
func NewGroupByCollectorWithValueMapper ¶
func NewGroupByCollectorWithValueMapper[T any, K comparable, V any]( keyMapper func(T) K, valueMapper func(T) (v V), ) Collector[T, map[K][]V, map[K][]V]
NewGroupByCollectorWithValueMapper returns a collector that accumulates the input elements into a map whose keys are the result of applying the provided mapping function to the input elements,
func NewJoiningCollector ¶
NewJoiningCollector returns a collector that concatenates the input elements, separated by the specified delimiter, in encounter order.
Note: This collector is not routine-safe.
func NewJoiningCollectorInParallel ¶
NewJoiningCollectorInParallel returns a collector that concatenates the input elements, separated by the specified delimiter, in encounter order.
Note: This collector is routine-safe.
func NewMaxCollector ¶
func NewMaxCollector[T any, R constraints.Ordered]( mapper func(T) R) Collector[T, *MaxContainer[R], R]
NewMaxCollector returns a Collector that computes the maximum of the elements of the stream.
Note: The returned Collector is not routine-safe.
func NewMaxCollectorInParallel ¶
func NewMaxCollectorInParallel[T any, R constraints.Ordered]( mapper func(T) R) Collector[T, *MaxContainer[R], R]
NewMaxCollectorInParallel returns a Collector that computes the maximum of the elements of the stream.
Note: The returned Collector is routine-safe.
func NewMinCollector ¶
func NewMinCollector[T any, R constraints.Ordered]( mapper func(T) R) Collector[T, *MinContainer[R], R]
NewMinCollector returns a Collector that computes the minimum of the elements of the stream.
Note: The returned Collector is not routine-safe.
func NewMinCollectorInParallel ¶
func NewMinCollectorInParallel[T any, R constraints.Ordered]( mapper func(T) R) Collector[T, *MinContainer[R], R]
NewMinCollectorInParallel returns a Collector that computes the minimum of the elements of the stream.
Note: The returned Collector is routine-safe.
func NewSumCollector ¶
func NewSumCollector[T any, R constraints.Integer | constraints.Float]( mapper func(T) R) Collector[T, *SumContainer[R], R]
NewSumCollector returns a Collector that sums the elements of the stream.
Note: The returned Collector is not routine-safe.
func NewSumCollectorInParallel ¶
func NewSumCollectorInParallel[T any, R constraints.Integer | constraints.Float]( mapper func(T) R) Collector[T, *SumContainer[R], R]
NewSumCollectorInParallel returns a Collector that sums the elements of the stream.
Note: The returned Collector is routine-safe.
func NewToMapCollector ¶
func NewToMapCollector[T any, K comparable]( size int, keyMapper func(T) K, ) Collector[T, map[K]T, map[K]T]
NewToMapCollector returns a collector that accumulates the input elements into a map whose keys and values are the result of applying the provided mapping functions to the input elements.
size is the expected size of the map.
keyMapper is a function that maps the input element to a key.
Note: If the input elements contain duplicate keys, will panic.
Note: This collector is not routine-safe.
func NewToMapCollectorWithDuplicateHandler ¶
func NewToMapCollectorWithDuplicateHandler[T any, K comparable, V any]( size int, keyMapper func(T) K, valueMapper func(T) V, duplicateHandler func(duplicateKey K, existingValue V, newValue V) V, ) Collector[T, map[K]V, map[K]V]
NewToMapCollectorWithDuplicateHandler returns a collector that accumulates the input elements into a map whose keys and values are the result of applying the provided mapping functions to the input elements.
size is the expected size of the map.
keyMapper is a function that maps the input element to a key.
valueMapper is a function that maps the input element to a value.
duplicateHandler is a function that handles the duplicate key. If it is nil, will ignore the duplicate key.
Note: This collector is not routine-safe.
func NewToMapWithIgnoreDuplicateCollector ¶
func NewToMapWithIgnoreDuplicateCollector[T any, K comparable]( size int, keyMapper func(T) K, ) Collector[T, map[K]T, map[K]T]
NewToMapWithIgnoreDuplicateCollector returns a collector that accumulates the input elements into a map whose keys and values are the result of applying the provided mapping functions to the input elements.
size is the expected size of the map.
keyMapper is a function that maps the input element to a key.
Note: If the input elements contain duplicate keys, the last one will be kept.
Note: This collector is not routine-safe.
func NewToSliceCollector ¶
func NewToSliceCollector[T any](size int) Collector[T, *SliceContainer[T], []T]
func NewToSliceCollectorInParallel ¶
func NewToSliceCollectorInParallel[T any](size int) Collector[T, *SliceContainer[T], []T]
type CountContainer ¶
type CountContainer struct {
// contains filtered or unexported fields
}
type CountContainerInParallel ¶
type CountContainerInParallel struct {
// contains filtered or unexported fields
}
type MaxContainer ¶
type MaxContainer[R constraints.Ordered] struct { // contains filtered or unexported fields }
type MinContainer ¶
type MinContainer[R constraints.Ordered] struct { // contains filtered or unexported fields }
type SliceContainer ¶
type SliceContainer[T any] struct { // contains filtered or unexported fields }
type SumContainer ¶
type SumContainer[R constraints.Integer | constraints.Float] struct { // contains filtered or unexported fields }