Documentation ¶
Overview ¶
Package stream provides a way to construct data processing streams from smaller pieces.
Index ¶
- Variables
- func Any[A any](xs Stream[A], p func(A) bool) bool
- func CollectCounter[A comparable](xs Stream[A]) fun.Counter[A]
- func CollectToSet[A comparable](xs Stream[A]) fun.Set[A]
- func CollectToSlice[A any](xs Stream[A]) []A
- func Count[A any](xs Stream[A]) int
- func Find[A any](xs Stream[A], p func(A) bool) fun.Option[A]
- func ForEach[A any](xs Stream[A], f func(A))
- func Group[A any, K comparable](xs Stream[A], by func(A) K) map[K][]A
- func GroupAggregate[A, B any, K comparable](xs Stream[A], by func(A) K, aggregate func([]A) B) map[K]B
- func Head[A any](xs Stream[A]) fun.Option[A]
- func Reduce[A, B any](start A, op func(A, B) A, xs Stream[B]) A
- func Sum[A fun.Number](xs Stream[A]) A
- func ToCounterBy[A any, K comparable](xs Stream[A], by func(A) K) fun.Counter[K]
- type Chan
- type Dict
- type Int
- type PullFunc
- type PushFunc
- type PushFunc2
- type Slice
- type Stream
- func Chain[A any](xss ...Stream[A]) Stream[A]
- func Chunked[A any](xs Stream[A], n int) Stream[[]A]
- func DebugPrint[A any](prefix string, xs Stream[A]) Stream[A]
- func Filter[A any](xs Stream[A], p func(A) bool) Stream[A]
- func FlatMap[A, B any](xs Stream[A], f func(A) Stream[B]) Stream[B]
- func Flatten[A any](xs Stream[Stream[A]]) Stream[A]
- func FromMany[A any](as ...A) Stream[A]
- func Generate[A any](x0 A, f func(A) A) Stream[A]
- func Intersperse[A any](xs Stream[A], sep A) Stream[A]
- func Keys[K, V any](xs Stream2[K, V]) Stream[K]
- func Map[A, B any](xs Stream[A], f func(A) B) Stream[B]
- func MapFilter[A, B any](xs Stream[A], f func(A) fun.Option[B]) Stream[B]
- func NewGenerator[T any](f func(func(T))) Stream[T]
- func NewStreamEmpty[A any]() Stream[A]
- func Once[A any](a A) Stream[A]
- func Paged[A any](xs Stream[[]A]) Stream[A]
- func Range[N constraints.Ordered](start, end, step N) Stream[N]
- func Repeat[A any](xs Stream[A]) Stream[A]
- func Skip[A any](xs Stream[A], n int) Stream[A]
- func Take[A any](xs Stream[A], n int) Stream[A]
- func TakeWhile[A any](xs Stream[A], p func(A) bool) Stream[A]
- func Unique[A comparable](xs Stream[A]) Stream[A]
- func Values[K, V any](xs Stream2[K, V]) Stream[V]
- type Stream2
- type String
Constants ¶
This section is empty.
Variables ¶
var ErrBreak = errors.New("break prematurely")
var ErrPullEnd = errors.New("pull end prematurely")
Functions ¶
func CollectCounter ¶
func CollectCounter[A comparable](xs Stream[A]) fun.Counter[A]
CollectCounter consumes the stream makes Counter with count of how many times each element was seen.
func CollectToSet ¶
func CollectToSet[A comparable](xs Stream[A]) fun.Set[A]
CollectToSet executes the stream and collects all results to a set.
func CollectToSlice ¶
CollectToSlice executes the stream and collects all results to a slice.
func Group ¶
func Group[A any, K comparable](xs Stream[A], by func(A) K) map[K][]A
Group groups elements by a function that returns a key.
func GroupAggregate ¶
func GroupAggregate[A, B any, K comparable](xs Stream[A], by func(A) K, aggregate func([]A) B) map[K]B
GroupAggregate is a convenience function that groups and then maps the subslices.
func ToCounterBy ¶
func ToCounterBy[A any, K comparable](xs Stream[A], by func(A) K) fun.Counter[K]
ToCounterBy consumes the stream and returns Counter with count of how many times each key was seen.
Types ¶
type Dict ¶
type Dict[K comparable, V any] map[K]V
type Stream ¶
Iterator2 is iterator taking function which handles iteratee and returns whether to stop iteration. Returns error happened during iteration or ErrBreak if exited prematurely.
func Chunked ¶
Chunked groups elements by n and produces a stream of slices. Produced chunks must not be retained.
func DebugPrint ¶
DebugPrint prints every processed element, without changing it.
func Flatten ¶
Flatten simplifies a stream of streams to just the stream of values by concatenating all inner streams.
func Intersperse ¶
Intersperse adds a separator after each stream element.
func MapFilter ¶
MapFilter applies function to every element and leaves only elements that are not None.
func NewGenerator ¶
func NewStreamEmpty ¶
NewStreamEmpty returns an empty stream.
func Range ¶
func Range[N constraints.Ordered](start, end, step N) Stream[N]
Range makes stream starting with start, step equal to step and going up to end, but not including end.
func Unique ¶
func Unique[A comparable](xs Stream[A]) Stream[A]
Unique makes stream of unique elements.