Documentation
¶
Overview ¶
Package process contains a host of functions for transforming sequences into into other sequences.
Index ¶
- func AddFirst[A, T any](a A, s sequence.Sequence[T]) sequence.Sequence[sequence.Pair[A, T]]
- func AddSecond[T, B any](s sequence.Sequence[T], b B) sequence.Sequence[sequence.Pair[T, B]]
- func Buffer[T any](s sequence.Sequence[T]) sequence.Sequence[T]
- func Concat[T any](seqs ...sequence.Sequence[T]) sequence.Sequence[T]
- func Filter[T any](s sequence.Sequence[T], pred func(T) bool) sequence.Sequence[T]
- func FilterErr[T any](s sequence.Sequence[T], pred func(T) (bool, error)) sequence.Sequence[T]
- func FirstOnly[A, B any](s sequence.Sequence[sequence.Pair[A, B]]) sequence.Sequence[A]
- func Flatten[T any, S ~[]T](src sequence.Sequence[S]) sequence.Sequence[T]
- func Limit[T any](s sequence.Sequence[T], n int) sequence.Sequence[T]
- func Map[In, Out any](s sequence.Sequence[In], convert func(In) Out) sequence.Sequence[Out]
- func MapErr[In, Out any](s sequence.Sequence[In], convert func(In) (Out, error)) sequence.Sequence[Out]
- func MapFilter[In, Out any](s sequence.Sequence[In], convert func(In) (Out, bool, error)) sequence.Sequence[Out]
- func Materialize[T any](s sequence.Sequence[T]) sequence.Sequence[T]
- func Process[In, Out any](src sequence.Sequence[In], proc func(In, func(Out)) error) sequence.Sequence[Out]
- func SecondOnly[A, B any](s sequence.Sequence[sequence.Pair[A, B]]) sequence.Sequence[B]
- func SwapPairs[A, B any](s sequence.Sequence[sequence.Pair[A, B]]) sequence.Sequence[sequence.Pair[B, A]]
- func Zip[A, B any](aSeq sequence.Sequence[A], bSeq sequence.Sequence[B]) sequence.Sequence[sequence.Pair[A, B]]
- func ZipShortest[A, B any](aSeq sequence.Sequence[A], bSeq sequence.Sequence[B]) sequence.Sequence[sequence.Pair[A, B]]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddFirst ¶
AddFirst creates a sequence where each item is a pair of a constant value and a value from a given sequence. The constant value is the first item in the pair.
func AddSecond ¶
AddSecond creates a sequence where each item is a pair of a constant value and a value from a given sequence. The constant value is the second item in the pair.
func Buffer ¶
Buffer is like Materialize in that it keeps a cached copy of data from an underlying sequence, both for faster access and to support re-using a volatile sequence.
Unlike Materialize a buffered sequence fills it's storage as it delivers values to a client, so there is no wait when calling Buffer before using the new sequence, and an unused Buffer sequence takes up no additional memory aside from the generator itself. It's slightly slower as locks are needed to ensure multiple readers play well with the cache, as some may be updating the cache at the same time. This is not true of Materialize where every access after it's built is a read and can easily be parallelized.
func Concat ¶
Concat performs a concatenation of multiple sequences, where each sequence is iterated in turn until the final one is completed.
func Filter ¶
Filter takes an input sequence and creates a sequence where only the values that pass the provided predicate function will be emitted. The ouput sequence will be the same type as the input sequence.
func FilterErr ¶
FilterErr takes an input sequence and creates a sequence where only the values that pass the provided predicate function will be emitted. The ouput sequence will have the same element type as the input sequence.
FilterErr allows the callback to stop iteration with a generic error, or use ErrStopIteration to simply indicate that no more values should be proceed.
func FirstOnly ¶
FirstOnly takes a sequence of Pair values, and returns a sequence of just the first value from each pair.
func Flatten ¶
Flatten processes a sequence of slices, producing a new sequence of the element type, and iterating across each slice as it's pulled from the input.
func Limit ¶
Limit returns a sequence where only a given number of items can be accessed from the input sequence before hitting the end of the sequence.
func Map ¶
Map takes in an input sequence and returns a sequence where every input value is permuted by the provided convert function. The new sequence may be of a different type due to the conversion, but will have the same number of items.
func MapErr ¶
func MapErr[In, Out any](s sequence.Sequence[In], convert func(In) (Out, error)) sequence.Sequence[Out]
MapErr takes in an input sequence and returns a sequence where every input value is permuted by the provided convert function. The new sequence may be of a different type due to the conversion, but will have the same number of items.
MapErr allows the callback to stop iteration with a generic error, or use ErrStopIteration to simply indicate that no more values should be proceed.
func MapFilter ¶
func MapFilter[In, Out any](s sequence.Sequence[In], convert func(In) (Out, bool, error)) sequence.Sequence[Out]
MapFilter performs both a Map and Filter operation on the input sequence where the convert function returns both the new value, and a boolean to indicate if it should be added at all.
MapFilter allows the callback to stop iteration with a generic error, or use ErrStopIteration to simply indicate that no more values should be proceed.
func Materialize ¶
Materialize wraps a sequence by storing its results to an internal slice and then serving that back to anyone accessing it.
It serves as an easy way to wrap a VolatileSequence such that it can be used multiple times. Also, it can speed up processing if it is known the sequence is used multiple times, as after the first materialization all access is to the cached data itself.
The two main downsides are that all values that eventually become part of the materialized sequence must be held in memory at all times, and the entire sequence passed to Materialize will be processed immediately before returning the new sequence.
func Process ¶
func Process[In, Out any](src sequence.Sequence[In], proc func(In, func(Out)) error) sequence.Sequence[Out]
Process provides a method of generating a destination sequence from a given input sequence using a BEAM style emitter.
The proc callback receives each input item, one at a time, and calls the provided emmiter function to output zero, one, or many results from that single input value. It can also return an error to stop processing.
func SecondOnly ¶
SecondOnly takes a sequence of Pair values, and returns a sequence of just the second value from each pair.
func SwapPairs ¶
func SwapPairs[A, B any](s sequence.Sequence[sequence.Pair[A, B]]) sequence.Sequence[sequence.Pair[B, A]]
SwapPairs processes a sequence with Pair[A,B] elements to produce one where the elements in the pair are swapped (i.e. Pair[B,A]).
func Zip ¶
func Zip[A, B any](aSeq sequence.Sequence[A], bSeq sequence.Sequence[B]) sequence.Sequence[sequence.Pair[A, B]]
Zip combines two input sequences into a sequence of Pairs where each pair contains an item from the first sequence matched up with one from the second sequence. When one seqence ends, the zipped sequence continues producing Pairs where one element is the zero value until both sequences are finished.
Types ¶
This section is empty.