Documentation ¶
Index ¶
- Constants
- func Channel[T any](i Iterable[T]) <-chan T
- func Collect[T, U any](s Stream[T], c Collector[T, U]) U
- func Filter[E any](s []E, f Predicate[E]) []E
- func Find[E any](s []E, f Predicate[E]) *E
- func Fold[A, B any](s []A, a B, f Reducer[A, B]) B
- func Map[A, B any](s []A, f Function[A, B]) []B
- func Reduce[E any](s []E, f Reducer[E, E]) E
- func Sample[E any](s []E, f Sampler) []E
- func SliceCollector[T any](s Stream[T]) []T
- type BitSet
- type Collection
- func (c Collection[T]) Filter(f Predicate[T]) Collection[T]
- func (c Collection[T]) Find(f Predicate[T]) *T
- func (c Collection[T]) Fold(a T, f Reducer[T, T]) T
- func (c Collection[T]) Iterator() (Iterator[T], *T)
- func (c Collection[T]) Map(f Function[T, T]) Collection[T]
- func (c Collection[T]) Reduce(f Reducer[T, T]) T
- type CollectionError
- type Collector
- type Float
- type Function
- type Generator
- type Integer
- type Iterable
- type IterableIterator
- type Iterator
- type JoinPredicate
- type Monitor
- type Number
- type Pair
- type Predicate
- type Reducer
- type Reference
- type ReferencePair
- type Sampler
- type Stream
- type Streamer
- type Transformer
- func FilterStream[T any](f Predicate[*T]) Transformer[T, T]
- func FoldStream[T, U any](a U, f Reducer[*T, U]) Transformer[T, U]
- func MapStream[T, U any](f Function[*T, U]) Transformer[T, U]
- func ReduceStream[T any](f Reducer[*T, T]) Transformer[T, T]
- func SampleStream[T any](f Predicate[int]) Transformer[T, T]
- type ValuePair
- type Yield
Constants ¶
const ( // UIntSizeEncodingLength is the number of bits required to encode the size of a uint. UIntSizeEncodingLength = 5 + (^uint(0) >> 63) // UIntSize is the size of a uint in bits. UIntSize = 1 << UIntSizeEncodingLength )
Variables ¶
This section is empty.
Functions ¶
func Filter ¶
Filter returns a new slice containing all elements from `s` for which `f` evaluates to `true`.
func Find ¶
Find returns a poiner to the first element from `s` for which `f` evaluates to `true` or `nil` if no such element exists.
func Fold ¶
Fold applies `f` to each element of slice `s` and the current value of `a` and returns the final value of `a`.
func Map ¶
Map applies `f` to each element of slice `s` and returns a new slice containing the results.
func Reduce ¶
Reduce operates like Fold, but uses `s[0]` as the initial accumulator value and then folds `s[1:]`. If `s` is empty, Reduce panics.
func Sample ¶
Sample returns a new slice containing all elements from `s` whose index satisfies `f`.
Note that while Sample resembles Filter in that it returns a new slice containing a subset of the elements from `s`, Sample only considers the index of each element, whereas Filter considers the element's value itself.
func SliceCollector ¶
Types ¶
type Collection ¶
type Collection[T any] []T
func (Collection[T]) Filter ¶
func (c Collection[T]) Filter(f Predicate[T]) Collection[T]
func (Collection[T]) Find ¶
func (c Collection[T]) Find(f Predicate[T]) *T
func (Collection[T]) Fold ¶
func (c Collection[T]) Fold(a T, f Reducer[T, T]) T
func (Collection[T]) Iterator ¶
func (c Collection[T]) Iterator() (Iterator[T], *T)
func (Collection[T]) Map ¶
func (c Collection[T]) Map(f Function[T, T]) Collection[T]
func (Collection[T]) Reduce ¶
func (c Collection[T]) Reduce(f Reducer[T, T]) T
type CollectionError ¶
type CollectionError uint
const ( // ErrEmptySliceParameter occurs when a function is called with an empty slice parameter where a non-empty slice is required. ErrEmptySliceParameter CollectionError // ErrNotEnoughParameters occurs when Range is called with no parameters. ErrNotEnoughParameters // ErrTooManyParameters occurs when Range is called with more than three parameters. ErrTooManyParameters // ErrRangeStepZero occurs when Range is called with a step size of zero. ErrRangeStepIsZero // ErrEmptyStream occurs when an empty stream is passed where a non-empty stream is required. ErrEmptyStream // ErrSliceRangeOutOfBounds occurs when either end of a sub-slice is outside the source slide's range. ErrSliceRangeOutOfBounds // ErrIndexOutOfBounds occurs when an accessed index refers to memory outside the structure's allocated memory. ErrIndexOutOfBounds // ErrNegativeCapacity occurs when a negative capacity is passed to a function that requires a non-negative capacity. ErrNegativeCapacity )
func (CollectionError) Error ¶
func (e CollectionError) Error() string
type Float ¶
type Float = constraints.Float
type Generator ¶
func (Generator[T]) Iterator ¶
func (g Generator[T]) Iterator() (IterableIterator[*T], *T)
type Integer ¶
type Integer = constraints.Integer
type IterableIterator ¶
func Range ¶
func Range[T Number](options ...T) IterableIterator[*T]
type JoinPredicate ¶
A JoinPredicate is a function that checks whether two values satisfy some condition.
type Monitor ¶
type Monitor chan struct{}
A Monitor is a channel that can be used to synchronize goroutines.
func (Monitor) Close ¶
func (m Monitor) Close()
Close closes the monitor and notifies all goroutines waiting on the monitor.
type Pair ¶
type Pair[T, U any] struct { First T Second U }
A Pair is just what its name suggests
func CartesianProduct ¶
CartesianProduct returns an Iterable that iterates over all pairs of elements from `s` and `t`. It works like Join with a condition that always evaluates to `true`, but is faster because the condition is not actually evaluated.
func Join ¶
func Join[T, U any](s []T, t []U, f JoinPredicate[T, U]) []Pair[T, U]
Join returns an Iterable that iterates over all pairs of elements from `s` and `t` for which `f` evaluates to `true`.
type Reducer ¶
type Reducer[T, U any] func(U, T) U
A Reducer is a function that combines two values into one.
type ReferencePair ¶
A ReferencePair behaves like a Pair[*T, *U] but with its elements being dereferenced before access.
func NewReferencePair ¶
func NewReferencePair[T, U any](first *T, second *U) *ReferencePair[T, U]
func (*ReferencePair[T, U]) String ¶
func (p *ReferencePair[T, U]) String() string
String returns a string representation of the pair.
func (*ReferencePair[T, U]) Unpack ¶
func (p *ReferencePair[T, U]) Unpack() (T, U)
Unpack returns the dereferenced elements of the pair.
func (*ReferencePair[T, U]) Value ¶
func (p *ReferencePair[T, U]) Value() Pair[T, U]
Value returns a copy of the pair with its elements dereferenced.
type Sampler ¶
A Sampler is a function that checks whether a value's index satisfies some condition.
type Stream ¶
type Stream[T any] interface { Read() *T }
func FromInterfaceIterable ¶
func FromValueIterable ¶
type Transformer ¶
func FilterStream ¶
func FilterStream[T any](f Predicate[*T]) Transformer[T, T]
func FoldStream ¶
func FoldStream[T, U any](a U, f Reducer[*T, U]) Transformer[T, U]
func MapStream ¶
func MapStream[T, U any](f Function[*T, U]) Transformer[T, U]
func ReduceStream ¶
func ReduceStream[T any](f Reducer[*T, T]) Transformer[T, T]
func SampleStream ¶
func SampleStream[T any](f Predicate[int]) Transformer[T, T]
type ValuePair ¶
A ValuePair is an alias for Pair[T, U] that exists for the sake of naming consistency.