Documentation
¶
Index ¶
- func Process[Out, In any](in iter.Seq[In], ps ...Processor) iter.Seq[Out]
- func ProcessSlice[Out, In any](in []In, ps ...Processor) ([]Out, error)
- type Processor
- type ProcessorFunc
- func Exclude[T any](f func(T) bool) ProcessorFunc[T, T]
- func Filter[T any](f func(T) bool) ProcessorFunc[T, T]
- func Limit[T any](n int) ProcessorFunc[T, T]
- func Map[T, U any](f func(T) U) ProcessorFunc[T, U]
- func Materialize[T any]() ProcessorFunc[T, T]
- func Until[T any](f func(T) bool) ProcessorFunc[T, T]
- func While[T any](f func(T) bool) ProcessorFunc[T, T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Process ¶
Process applies the given Processors to the input iterator, returning a new iterator with the processed values. The Processors are combined using the Join function, which may panic if the Processors are not compatible. This function will also panic if the input iterator doesn't match the input type of the first Processor.
func ProcessSlice ¶
ProcessSlice applies the given Processors to the input slice, collecting the results into a new slice. Processors are combined using the Join function, which may panic if the Processors are not compatible. This function will also panic if the slice element type doesn't match the input type of the first Processor.
If an error is panic'd during execution of the iterator to produce the slice, that error is returned.
Types ¶
type Processor ¶
type Processor interface {
// contains filtered or unexported methods
}
Processor is an interface that represents a processing step in a pipeline. Processors can be composed together to form a larger pipeline.
func Join ¶ added in v0.0.8
Join creates a new Processor that represents a pipeline of the given Processors. The pipeline is validated to ensure that the input type of each Processor matches the output type of the previous Processor. If the validation fails, the function panics.
In the case that only one Processor is provided, it is returned as is. If the list of Processors is empty, it returns a Processor that acts as a no-op.
func TryJoin ¶ added in v0.0.8
TryJoin creates a new Processor that represents a pipeline of the given Processors. The pipeline is validated to ensure that the input type of each Processor matches the output type of the previous Processor. If the validation fails, an error is returned.
In the case that only one Processor is provided, it is returned as is. If the list of Processors is empty, it returns a Processor that acts as a no-op.
type ProcessorFunc ¶
ProcessorFunc is a function type that implements the Processor interface. It takes an iterater of type T and returns an iterator of type U.
func Exclude ¶
func Exclude[T any](f func(T) bool) ProcessorFunc[T, T]
Exclude returns a new iterator that filters the input iterator by applying the given predicate function, returning only the elements for which the predicate function returns false.
func Filter ¶
func Filter[T any](f func(T) bool) ProcessorFunc[T, T]
Filter returns a new iterator that filters the input iterator by applying the given predicate function, returning only the elements for which the predicate function returns true.
func Limit ¶
func Limit[T any](n int) ProcessorFunc[T, T]
Limit returns a new iterator that provides a most the first n elements of the input iterator.
func Map ¶
func Map[T, U any](f func(T) U) ProcessorFunc[T, U]
Map applies the given function f to each element in the input iterator, returning a new iterator with the transformed elements.
func Materialize ¶
func Materialize[T any]() ProcessorFunc[T, T]
Materialize returns a new iterator that materializes the input iterator, ensuring that all elements are evaluated once and stored in memory. This can be useful when you want to reuse an iterator multiple times without re-evaluating the input iterator, such as when the input is expensive to evaluate or when it can only be evaluated once.
func Until ¶
func Until[T any](f func(T) bool) ProcessorFunc[T, T]
Until returns a new iterator that yields elements from the given iterator function it as long as the provided predicate function returns false.
func While ¶
func While[T any](f func(T) bool) ProcessorFunc[T, T]
While returns a new iterator that yields elements from the given iterator function it as long as the provided predicate function returns true.