process

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package process contains a host of functions for transforming sequences into into other sequences.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFirst

func AddFirst[A, T any](a A, s sequence.Sequence[T]) sequence.Sequence[sequence.Pair[A, T]]

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

func AddSecond[T, B any](s sequence.Sequence[T], b B) sequence.Sequence[sequence.Pair[T, B]]

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

func Buffer[T any](s sequence.Sequence[T]) sequence.Sequence[T]

Buffer is an alternative to the Materialize method 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 read-only, and can easily be parallelized.

func Concat

func Concat[T any](seqs ...sequence.Sequence[T]) sequence.Sequence[T]

Concat performs a concatenation of multiple sequences, where each sequence is iterated in turn until the final one is completed.

func Filter

func Filter[T any](s sequence.Sequence[T], pred func(T) bool) sequence.Sequence[T]

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

func FilterErr[T any](s sequence.Sequence[T], pred func(T) (bool, error)) sequence.Sequence[T]

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

func FirstOnly[A, B any](s sequence.Sequence[sequence.Pair[A, B]]) sequence.Sequence[A]

FirstOnly takes a sequence of Pair values, and returns a sequence of just the first value from each pair.

func Flatten

func Flatten[T any, S ~[]T](src sequence.Sequence[S]) sequence.Sequence[T]

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

func Limit[T any](s sequence.Sequence[T], n int) sequence.Sequence[T]

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

func Map[In, Out any](s sequence.Sequence[In], convert func(In) Out) sequence.Sequence[Out]

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 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

func SecondOnly[A, B any](s sequence.Sequence[sequence.Pair[A, B]]) sequence.Sequence[B]

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.

func ZipShortest

func ZipShortest[A, B any](aSeq sequence.Sequence[A], bSeq sequence.Sequence[B]) sequence.Sequence[sequence.Pair[A, B]]

ZipShortest is like Zip, but stops once one sequence is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL