Documentation ¶
Index ¶
- func NewAvgCollector[T any, R constraints.Integer | constraints.Float](mapper func(T) R) (supplier func() any, accumulator func(container, item any), ...)
- func NewCountCollector[T any]() (supplier func() any, accumulator func(container, item any), ...)
- func NewGroupByCollector[T any, K comparable](keyMapper func(T) K) (supplier func() any, accumulator func(container, item any), ...)
- func NewJoiningCollector[T any](separator string) (supplier func() any, accumulator func(container, item any), ...)
- func NewMaxCollector[T any, R constraints.Ordered](mapper func(T) R) (supplier func() any, accumulator func(container, item any), ...)
- func NewMinCollector[T any, R constraints.Ordered](mapper func(T) R) (supplier func() any, accumulator func(container, item any), ...)
- func NewSumCollector[T any, R constraints.Integer | constraints.Float](mapper func(T) R) (supplier func() any, accumulator func(container, item any), ...)
- func NewToMapCollector[T any, K comparable](size int, keyMapper func(T) K) (supplier func() any, accumulator func(container, item any), ...)
- func NewToMapCollectorWithDuplicateHandler[T any, K comparable, V any](size int, keyMapper func(T) K, valueMapper func(T) V, ...) (supplier func() any, accumulator func(container, item any), ...)
- func NewToMapWithIgnoreDuplicateCollector[T any, K comparable](size int, keyMapper func(T) K) (supplier func() any, accumulator func(container, item any), ...)
- func NewToSliceCollector[T any](size int) (supplier func() any, accumulator func(container, item any), ...)
- func WithParallelism(parallelism uint) func(Stream)
- func WithSync() func(Stream)
- type AccumulatorFunc
- type ConsumeFunc
- type DistinctFunc
- type FilterFunc
- type FlatMapFunc
- type GenerateFunc
- type LessFunc
- type MapFunc
- type MatchFunc
- type Option
- type Stream
- type SupplierFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAvgCollector ¶
func NewAvgCollector[T any, R constraints.Integer | constraints.Float]( mapper func(T) R) ( supplier func() any, accumulator func(container, item any), finisher func(container any) any, )
func NewCountCollector ¶
func NewGroupByCollector ¶
func NewJoiningCollector ¶
func NewMaxCollector ¶
func NewMinCollector ¶
func NewSumCollector ¶
func NewSumCollector[T any, R constraints.Integer | constraints.Float]( mapper func(T) R) ( supplier func() any, accumulator func(container, item any), finisher func(container any) any, )
func NewToMapCollector ¶
func NewToMapCollector[T any, K comparable]( size int, keyMapper func(T) K, ) ( supplier func() any, accumulator func(container, item any), finisher func(container any) any, )
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, ) ( supplier func() any, accumulator func(container, item any), finisher func(container any) any, )
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, ) ( supplier func() any, accumulator func(container, item any), finisher func(container any) any, )
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 WithParallelism ¶
WithParallelism returns an option that sets the parallelism of the stream
Types ¶
type AccumulatorFunc ¶
type ConsumeFunc ¶
type ConsumeFunc func(item any)
type DistinctFunc ¶
type FilterFunc ¶
type FlatMapFunc ¶
type GenerateFunc ¶
type GenerateFunc func(source chan<- any)
source is the channel that the generator function writes to, and the generator should not close the channel
type MatchFunc ¶
type MatchFunc FilterFunc
type Stream ¶
type Stream interface { // Map applies the given mapper to each item in the stream Map(mapper MapFunc, opts ...Option) Stream // FlatMap applies the given mapper to each item in the stream FlatMap(mapper FlatMapFunc, opts ...Option) Stream // Filter filters the stream by the given predicate Filter(filter FilterFunc, opts ...Option) Stream // Concat concatenates the given streams to the current stream Concat(streams []Stream, opts ...Option) Stream // Sort sorts the stream by the given less function Sort(less LessFunc, opts ...Option) Stream // Distinct removes the duplicate items in the stream Distinct(distinct DistinctFunc, opts ...Option) Stream // Skip skips the first n items in the stream Skip(limit int64, opts ...Option) Stream // Limit limits the number of items in the stream Limit(limit int64, opts ...Option) Stream // TakeWhile takes items from the stream while the given predicate is true. // The first item that makes the predicate false will stop the stream. // // This is a short-circuiting terminal operation. TakeWhile(match MatchFunc, opts ...Option) Stream // DropWhile drops items from the stream while the given predicate is true. // The first item that makes the predicate false will start the stream. DropWhile(match MatchFunc, opts ...Option) Stream // Peek applies the given consumer to each item in the stream Peek(consumer ConsumeFunc, opts ...Option) Stream // AnyMatch returns true if any item in the stream matches the given predicate, otherwise false. // If the stream is empty, false is returned. // // This is a short-circuiting terminal operation. AnyMatch(match MatchFunc, opts ...Option) bool // AllMatch returns true if all items in the stream match the given predicate, otherwise false. // If the stream is empty, true is returned. // // This is a short-circuiting terminal operation. AllMatch(match MatchFunc, opts ...Option) bool // NoneMatch returns true if no item in the stream matches the given predicate, otherwise false. // If the stream is empty, true is returned. // // This is a short-circuiting terminal operation. NoneMatch(match MatchFunc, opts ...Option) bool // FindFirst returns the first item in the stream. // If the stream is empty, nil is returned. // // If the stream has no encounter order, then any element may be returned. // // This is a short-circuiting terminal operation. FindFirst(opts ...Option) (item any, found bool) // Count returns the number of items in the stream. // If the count is greater than math.MaxInt64, math.MaxInt64 is returned. Count(opts ...Option) int64 // Reduce reduces the stream to a single value by the given accumulator function. Reduce(identity any, accumulator AccumulatorFunc, opts ...Option) any // ForEach applies the given consumer to each item in the stream ForEach(consumer ConsumeFunc, opts ...Option) // ToIfaceSlice returns the stream as a slice of interface{} ToIfaceSlice(opts ...Option) []any // ApplyOptions applies the given options to the stream ApplyOptions(opts ...Option) Stream // Collect collects the stream to a supplier of the given type. // // You usually don't need to set these 3 parameters directly unless you want to customize the collector. // Here are some common collectors: // - NewToMapCollector // - NewToMapWithIgnoreDuplicateCollector // - NewToMapCollectorWithDuplicateHandler // - NewToSliceCollector // - NewJoiningCollector // - NewGroupByCollector // - NewCountCollector // - NewSumCollector // - NewAvgCollector // - NewMaxCollector // - NewMinCollector // // Please refer to the example in collectors_test.go for more details. Collect( supplier func() any, accumulator func(container, item any), finisher func(container any) any, ) any // Close closes the stream Close() }
Stream is the interface for a stream
func From ¶
func From(generator GenerateFunc, opts ...Option) Stream
From returns a stream from the given generator function
type SupplierFunc ¶
type SupplierFunc func() any