Documentation ¶
Index ¶
- func NewYeti() internalpipe.YeetSnag
- func Reduce[SrcT, DstT any](p Piper[SrcT], fn func(*DstT, *SrcT) DstT, initVal ...DstT) DstT
- type Accum
- type Comparator
- type Pipe
- func (p *Pipe[T]) Any() *T
- func (p *Pipe[T]) Count() int
- func (p *Pipe[T]) Do() []T
- func (p *Pipe[T]) Entrails() *internalpipe.Pipe[T]
- func (p *Pipe[T]) Erase() Piper[any]
- func (p *Pipe[T]) Filter(fn Predicate[T]) Piper[T]
- func (p *Pipe[T]) First() *T
- func (p *Pipe[T]) Map(fn func(T) T) Piper[T]
- func (p *Pipe[T]) MapFilter(fn func(T) (T, bool)) Piper[T]
- func (p *Pipe[T]) Parallel(n uint16) Piper[T]
- func (p *Pipe[T]) Promices() []func() (T, bool)
- func (p *Pipe[T]) Reduce(fn Accum[T]) *T
- func (p *Pipe[T]) Snag(h func(error)) Piper[T]
- func (p *Pipe[T]) Sort(less Comparator[T]) Piper[T]
- func (p *Pipe[T]) Sum(plus Accum[T]) T
- func (p *Pipe[T]) Yeti(y internalpipe.YeetSnag) Piper[T]
- type PipeNL
- func (p *PipeNL[T]) Any() *T
- func (p *PipeNL[T]) Entrails() *internalpipe.Pipe[T]
- func (p *PipeNL[T]) Erase() PiperNoLen[any]
- func (p *PipeNL[T]) Filter(fn Predicate[T]) PiperNoLen[T]
- func (p *PipeNL[T]) First() *T
- func (p *PipeNL[T]) Gen(n int) Piper[T]
- func (p *PipeNL[T]) Map(fn func(T) T) PiperNoLen[T]
- func (p *PipeNL[T]) MapFilter(fn func(T) (T, bool)) PiperNoLen[T]
- func (p *PipeNL[T]) Parallel(n uint16) PiperNoLen[T]
- func (p *PipeNL[T]) Snag(h func(error)) PiperNoLen[T]
- func (p *PipeNL[T]) Take(n int) Piper[T]
- func (p *PipeNL[T]) Yeti(y internalpipe.YeetSnag) PiperNoLen[T]
- type Piper
- func Collect[DstT any](p Piper[any]) Piper[DstT]
- func Map[SrcT any, DstT any](p Piper[SrcT], fn func(x SrcT) DstT) Piper[DstT]
- func MapFilter[SrcT, DstT any](p Piper[SrcT], fn func(x SrcT) (DstT, bool)) Piper[DstT]
- func Range[T constraints.Integer | constraints.Float](start, finish, step T) Piper[T]
- func Repeat[T any](x T, n int) Piper[T]
- func Slice[T any](dt []T) Piper[T]
- type PiperNoLen
- func CollectNL[DstT any](p PiperNoLen[any]) PiperNoLen[DstT]
- func Cycle[T any](a []T) PiperNoLen[T]
- func Fn[T any](fn func(i int) T) PiperNoLen[T]
- func Func[T any](fn func(i int) (T, bool)) PiperNoLen[T]
- func FuncP[T any](fn func(i int) (*T, bool)) PiperNoLen[T]
- func MapFilterNL[SrcT, DstT any](p PiperNoLen[SrcT], fn func(x SrcT) (DstT, bool)) PiperNoLen[DstT]
- func MapNL[SrcT, DstT any](p PiperNoLen[SrcT], fn func(x SrcT) DstT) PiperNoLen[DstT]
- type Predicate
- type Promice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewYeti ¶ added in v1.0.5
func NewYeti() internalpipe.YeetSnag
NewYeti creates a brand new Yeti - an object for error handling.
Types ¶
type Accum ¶
type Accum[T any] func(*T, *T) T
Accum is a standard type for reduce function. It is guaranteed that arguments are not nil, so you can dereference them with no check.
type Comparator ¶
Comparator is a standard type for sorting comparisons. It is guaranteed that argument is not nil, so you can dereference it with no check.
func Comp ¶
func Comp[T any](cmp func(T, T) bool) Comparator[T]
Comp creates a Comparator from a function of a different signature. Using it allows inner function `cmp` not to use dereference, but also it leads to a larger memory allocation.
type Pipe ¶
type Pipe[T any] struct { internalpipe.Pipe[T] }
Pipe implements the pipe on any slice. Pipe may be initialized with `Slice`, `Func`, `Cycle` or `Range`.
func (*Pipe[T]) Any ¶
func (p *Pipe[T]) Any() *T
Any returns a pointer to a random element in the pipe or nil if none left.
func (*Pipe[T]) Do ¶
func (p *Pipe[T]) Do() []T
Do evaluates all the pipeline and returns the result slice.
func (*Pipe[T]) Entrails ¶
func (p *Pipe[T]) Entrails() *internalpipe.Pipe[T]
Entrails is an out-of-Piper interface method to provide Map[T1 -> T2].
func (*Pipe[T]) Erase ¶ added in v1.0.5
Erase wraps all pipe values to interface{} type, so you are able to use pipe methods with type convertions. You can use collectors from collectiors.go file of this package to collect results into a particular type.
func (*Pipe[T]) Map ¶
Map applies given function to each element of the underlying slice returns the slice where each element is n[i] = f(p[i]).
func (*Pipe[T]) MapFilter ¶ added in v1.0.5
MapFilter applies given function to each element of the underlying slice, if the second returning value of fn is false, the element is skipped (may be useful for error handling). returns the slice where each element is n[i] = f(p[i]) if it is not skipped.
func (*Pipe[T]) Parallel ¶
Parallel set n - the amount of goroutines to run on. Only the first Parallel() in a pipe chain is applied.
func (*Pipe[T]) Promices ¶ added in v1.0.5
Promices returns an array of Promice values - functions to be evaluated to get the value on i'th place. Promice returns two values: the evaluated value and if it is not skipped.
func (*Pipe[T]) Reduce ¶
Reduce applies the result of a function to each element one-by-one: f(p[n], f(p[n-1], f(p[n-2, ...]))). It is recommended to use reducers from the default reducer if possible to decrease memory allocations.
func (*Pipe[T]) Sort ¶
func (p *Pipe[T]) Sort(less Comparator[T]) Piper[T]
Sort sorts the underlying slice on a current step of a pipeline.
type PipeNL ¶
type PipeNL[T any] struct { internalpipe.Pipe[T] }
PipeNL implements the pipe on any slice. PipeNL may be initialized with `Slice`, `Func`, `Cycle` or `Range`.
func (*PipeNL[T]) Any ¶
func (p *PipeNL[T]) Any() *T
Any returns a pointer to a random element in the pipe or nil if none left.
func (*PipeNL[T]) Entrails ¶
func (p *PipeNL[T]) Entrails() *internalpipe.Pipe[T]
Entrails is an out of Piper interface method to provide Map[T1 -> T2].
func (*PipeNL[T]) Erase ¶ added in v1.0.5
func (p *PipeNL[T]) Erase() PiperNoLen[any]
Erase wraps all pipe values to interface{} type, so you are able to use pipe methods with type convertions. You can use collectors from collectiors.go file of this package to collect results into a particular type.
func (*PipeNL[T]) Filter ¶
func (p *PipeNL[T]) Filter(fn Predicate[T]) PiperNoLen[T]
Filter leaves only items with true predicate fn.
func (*PipeNL[T]) First ¶
func (p *PipeNL[T]) First() *T
First returns the first element of the pipe.
func (*PipeNL[T]) Gen ¶
Gen set the amount of values to generate as initial array. It's applied only the first Gen() or Take() function in the pipe.
func (*PipeNL[T]) Map ¶
func (p *PipeNL[T]) Map(fn func(T) T) PiperNoLen[T]
Map applies given function to each element of the underlying slice returns the slice where each element is n[i] = f(p[i]).
func (*PipeNL[T]) MapFilter ¶ added in v1.0.5
func (p *PipeNL[T]) MapFilter(fn func(T) (T, bool)) PiperNoLen[T]
MapFilter applies given function to each element of the underlying slice, if the second returning value of fn is false, the element is skipped (may be useful for error handling). returns the slice where each element is n[i] = f(p[i]) if it is not skipped.
func (*PipeNL[T]) Parallel ¶
func (p *PipeNL[T]) Parallel(n uint16) PiperNoLen[T]
Parallel set n - the amount of goroutines to run on. Only the first Parallel() in a pipe chain is applied.
func (*PipeNL[T]) Snag ¶ added in v1.0.5
func (p *PipeNL[T]) Snag(h func(error)) PiperNoLen[T]
Snag links an error handler to the previous Pipe method.
func (*PipeNL[T]) Take ¶
Take is used to set the amount of values expected to be in result slice. It's applied only the first Gen() or Take() function in the pipe.
func (*PipeNL[T]) Yeti ¶ added in v1.0.5
func (p *PipeNL[T]) Yeti(y internalpipe.YeetSnag) PiperNoLen[T]
Yeti links a yeti error handler to the Pipe.
type Piper ¶
type Piper[T any] interface { // contains filtered or unexported methods }
Piper interface contains all methods of a pipe with determened length.
func Collect ¶ added in v1.0.5
Collect translates Piper with erased type (achieved by calling an Erase method of any type).
func MapFilter ¶ added in v1.0.6
MapFilter applies function on a Piper of type SrcT and returns a Pipe of type DstT. fn returns a value of DstT type and true if this value is not skipped.
func Range ¶
func Range[T constraints.Integer | constraints.Float](start, finish, step T) Piper[T]
Range creates a lazy sequence of type 'T', which consists of values starting from 'start', incrementing by 'step' and stopping just before 'finish', i.e. [start..finish). The type 'T' can be either an integer or a float.
type PiperNoLen ¶
type PiperNoLen[T any] interface { // contains filtered or unexported methods }
PiperNoLen represents methods available to a Pipe type with no length determened.
func CollectNL ¶ added in v1.0.5
func CollectNL[DstT any](p PiperNoLen[any]) PiperNoLen[DstT]
CollectNL translates PiperNL with erased type (achieved by calling an Erase method of any type).
func Cycle ¶
func Cycle[T any](a []T) PiperNoLen[T]
Cycle creates a lazy sequence that cycles through the elements of the provided slice 'a'. To use the resulting sequence, the 'Cycle' function returns a 'PiperNoLen' object.
Use the 'Take' or 'Gen' functions to set the number of output values to generate, or use the 'Until' function to enforce a limit based on a predicate function.
func Fn ¶
func Fn[T any](fn func(i int) T) PiperNoLen[T]
Fu creates a lazy sequence by applying the provided function 'fn' to each index 'i', and setting the result to the sequence at index 'i'.
'fn' is a shortened version of the 'Func' function, where the second argument is true by default.
Use the 'Take' or 'Gen' functions to set the number of output values to generate, or use the 'Until' function to enforce a limit based on a predicate function.
func Func ¶
func Func[T any](fn func(i int) (T, bool)) PiperNoLen[T]
Func creates a lazy sequence by applying the provided function 'fn' to each index 'i', placing the resulting object into the sequence at index 'i'.
The 'fn' function must return an object of type T, along with a boolean indicating if it exists.
Use the 'Take' or 'Gen' functions to set the number of output values to generate, or use the 'Until' function to enforce a limit based on a predicate function.
func FuncP ¶
func FuncP[T any](fn func(i int) (*T, bool)) PiperNoLen[T]
FuncP is the same as Func but allows to return pointers to the values. It creates a lazy sequence by applying the provided function 'fn' to each index 'i', and setting the result to the sequence at index 'i' as a pointer to the object of type 'T'.
'fn' should return a pointer to an object of type 'T', along with a boolean indicating whether the object exists.
Use the 'Take' or 'Gen' functions to set the number of output values to generate, or use the 'Until' function to enforce a limit based on a predicate function.
func MapFilterNL ¶ added in v1.0.6
func MapFilterNL[SrcT, DstT any]( p PiperNoLen[SrcT], fn func(x SrcT) (DstT, bool), ) PiperNoLen[DstT]
MapFilterNL applies function on a PiperNoLen of type SrcT and returns a Pipe of type DstT. fn returns a value of DstT type and true if this value is not skipped.
func MapNL ¶
func MapNL[SrcT, DstT any]( p PiperNoLen[SrcT], fn func(x SrcT) DstT, ) PiperNoLen[DstT]
MapNL applies function on a PiperNoLen of type SrcT and returns a Pipe of type DstT.