Documentation
¶
Index ¶
- func Collect[T, R any](stream *Stream[T], collector ResultCollector[T, R]) R
- func Reduce[T, R any](stream *Stream[T], initial R, reducer func(acc R, value T) R) R
- type Collector
- type ResultCollector
- func CountingBy[T any, K comparable](key func(T) K) ResultCollector[T, map[K]int]
- func GroupingBy[T any, K comparable](key func(T) K) ResultCollector[T, map[K][]T]
- func ToMap[T any, K comparable, R any](mapper func(T) (K, R)) ResultCollector[T, map[K]R]
- func ToMultiMap[T any, K comparable, R any](mapper func(T) (K, R)) ResultCollector[T, map[K][]R]
- func ToSlice[T any]() ResultCollector[T, []T]
- func ToSliceCopy[T any]() ResultCollector[T, []T]
- type ResultCollectorFunc
- type Stream
- func Compact[T comparable](stream *Stream[T]) *Stream[T]
- func Distinct[T comparable](stream *Stream[T]) *Stream[T]
- func DistinctBy[T any, K comparable](stream *Stream[T], key func(T) K) *Stream[T]
- func Empty[T any]() *Stream[T]
- func FlatMap[T, R any](stream *Stream[T], mapper func(T) []R) *Stream[R]
- func From[T any](values ...T) *Stream[T]
- func Generate[T any](count int, supplier func(index int) T) *Stream[T]
- func Iterate[T any](seed T, count int, next func(T) T) *Stream[T]
- func Map[T, R any](stream *Stream[T], mapper func(T) R) *Stream[R]
- func Of[T any](values []T) *Stream[T]
- func Sorted[T cmp.Ordered](stream *Stream[T]) *Stream[T]
- func (s *Stream[T]) AllMatch(predicate func(T) bool) bool
- func (s *Stream[T]) AnyMatch(predicate func(T) bool) bool
- func (s *Stream[T]) Collect() []T
- func (s *Stream[T]) CollectCopy() []T
- func (s *Stream[T]) CollectToMap(mapper func(T) (any, any)) map[any]any
- func (s *Stream[T]) CollectToMultiMap(mapper func(T) (any, any)) map[any][]any
- func (s *Stream[T]) CollectWith(collector func([]T) any) any
- func (s *Stream[T]) CompactFunc(empty func(T) bool) *Stream[T]
- func (s *Stream[T]) Count() int
- func (s *Stream[T]) DistinctBy(key func(T) string) *Stream[T]
- func (s *Stream[T]) DropWhile(predicate func(T) bool) *Stream[T]
- func (s *Stream[T]) Filter(predicate func(T) bool) *Stream[T]
- func (s *Stream[T]) FilterOut(predicate func(T) bool) *Stream[T]
- func (s *Stream[T]) Find(predicate func(T) bool) *T
- func (s *Stream[T]) FindIndex(predicate func(T) bool) int
- func (s *Stream[T]) FlatMap(mapper func(T) []T) *Stream[T]
- func (s *Stream[T]) ForEach(action func(T))
- func (s *Stream[T]) Limit(n int) *Stream[T]
- func (s *Stream[T]) Map(mapper func(T) any) *TerminalStream[any]
- func (s *Stream[T]) NoneMatch(predicate func(T) bool) bool
- func (s *Stream[T]) Peek(action func(T)) *Stream[T]
- func (s *Stream[T]) Reduce(initial T, reducer func(acc T, value T) T) T
- func (s *Stream[T]) Reverse() *Stream[T]
- func (s *Stream[T]) Skip(n int) *Stream[T]
- func (s *Stream[T]) Sort(less func(a, b T) bool) *Stream[T]
- func (s *Stream[T]) TakeWhile(predicate func(T) bool) *Stream[T]
- func (s *Stream[T]) ToTerminal() *TerminalStream[T]
- func (s *Stream[T]) Transform(mapper func(T) T) *Stream[T]
- type TerminalStream
- func (s *TerminalStream[T]) Collect() []T
- func (s *TerminalStream[T]) CollectCopy() []T
- func (s *TerminalStream[T]) CollectToMap(mapper func(T) (any, T)) map[any][]T
- func (s *TerminalStream[T]) ParallelExecute(fn func(int, *T), parallelism int)
- func (s *TerminalStream[T]) ParallelExecuteWithTimeout(fn func(int, T), cancel func(int, T), timeout time.Duration, parallelism int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collect ¶
func Collect[T, R any](stream *Stream[T], collector ResultCollector[T, R]) R
Collect applies a typed collector to a stream.
Types ¶
type ResultCollector ¶
type ResultCollector[T, R any] interface { Collect(values []T) R }
ResultCollector collects stream values into a custom result.
func CountingBy ¶
func CountingBy[T any, K comparable](key func(T) K) ResultCollector[T, map[K]int]
CountingBy creates a collector that counts stream values by key.
func GroupingBy ¶
func GroupingBy[T any, K comparable](key func(T) K) ResultCollector[T, map[K][]T]
GroupingBy creates a collector that groups stream values by key.
func ToMap ¶
func ToMap[T any, K comparable, R any](mapper func(T) (K, R)) ResultCollector[T, map[K]R]
ToMap creates a collector that maps stream values into a map.
func ToMultiMap ¶
func ToMultiMap[T any, K comparable, R any](mapper func(T) (K, R)) ResultCollector[T, map[K][]R]
ToMultiMap creates a collector that maps stream values into grouped map values.
func ToSlice ¶
func ToSlice[T any]() ResultCollector[T, []T]
ToSlice creates a collector that returns stream values.
func ToSliceCopy ¶
func ToSliceCopy[T any]() ResultCollector[T, []T]
ToSliceCopy creates a collector that returns a copy of stream values.
type ResultCollectorFunc ¶
type ResultCollectorFunc[T, R any] func(values []T) R
ResultCollectorFunc adapts a function to ResultCollector.
func (ResultCollectorFunc[T, R]) Collect ¶
func (f ResultCollectorFunc[T, R]) Collect(values []T) R
Collect adapts a function to ResultCollector.
type Stream ¶
type Stream[T any] struct { // contains filtered or unexported fields }
Stream wraps a slice and exposes fluent collection operations.
func Compact ¶
func Compact[T comparable](stream *Stream[T]) *Stream[T]
Compact removes zero values from a comparable stream.
func Distinct ¶
func Distinct[T comparable](stream *Stream[T]) *Stream[T]
Distinct keeps the first occurrence of each comparable value.
func DistinctBy ¶
func DistinctBy[T any, K comparable](stream *Stream[T], key func(T) K) *Stream[T]
DistinctBy keeps the first value for each comparable key.
func (*Stream[T]) CollectCopy ¶
func (s *Stream[T]) CollectCopy() []T
CollectCopy returns a copy of stream values.
func (*Stream[T]) CollectToMap ¶
CollectToMap collects stream values into a map. Duplicate keys are overwritten.
func (*Stream[T]) CollectToMultiMap ¶
CollectToMultiMap collects stream values into a grouped map.
func (*Stream[T]) CollectWith ¶
CollectWith collects stream values using a custom collector.
func (*Stream[T]) CompactFunc ¶
CompactFunc removes values matching empty.
func (*Stream[T]) DistinctBy ¶
DistinctBy keeps the first value for each string key.
func (*Stream[T]) ForEach ¶
func (s *Stream[T]) ForEach(action func(T))
ForEach executes action for each value.
func (*Stream[T]) Map ¶
func (s *Stream[T]) Map(mapper func(T) any) *TerminalStream[any]
Map maps values into any and returns a terminal stream for legacy compatibility.
func (*Stream[T]) Reduce ¶
func (s *Stream[T]) Reduce(initial T, reducer func(acc T, value T) T) T
Reduce folds values into one value.
func (*Stream[T]) ToTerminal ¶
func (s *Stream[T]) ToTerminal() *TerminalStream[T]
ToTerminal converts a stream to a terminal stream.
type TerminalStream ¶
type TerminalStream[T any] struct { // contains filtered or unexported fields }
TerminalStream represents a stream that can only be collected or executed.
func NewTerminalStream ¶
func NewTerminalStream[T any](values []T) *TerminalStream[T]
NewTerminalStream creates a terminal stream from values.
func (*TerminalStream[T]) Collect ¶
func (s *TerminalStream[T]) Collect() []T
Collect returns terminal stream values.
func (*TerminalStream[T]) CollectCopy ¶
func (s *TerminalStream[T]) CollectCopy() []T
CollectCopy returns a copy of terminal stream values.
func (*TerminalStream[T]) CollectToMap ¶
func (s *TerminalStream[T]) CollectToMap(mapper func(T) (any, T)) map[any][]T
CollectToMap collects terminal stream values into a multimap.
func (*TerminalStream[T]) ParallelExecute ¶
func (s *TerminalStream[T]) ParallelExecute(fn func(int, *T), parallelism int)
ParallelExecute executes fn concurrently on each stream value.
func (*TerminalStream[T]) ParallelExecuteWithTimeout ¶
func (s *TerminalStream[T]) ParallelExecuteWithTimeout(fn func(int, T), cancel func(int, T), timeout time.Duration, parallelism int)
ParallelExecuteWithTimeout executes fn concurrently and calls cancel when an item exceeds timeout.