internalpipe

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccumFn

type AccumFn[T any] func(*T, *T) T

type ErrHandler added in v1.0.5

type ErrHandler func(error)

type GeneratorFn

type GeneratorFn[T any] func(int) (*T, bool)

type Pipe

type Pipe[T any] struct {
	Fn            GeneratorFn[T]
	Len           int
	ValLim        int
	GoroutinesCnt int
	// contains filtered or unexported fields
}

func Cycle added in v1.0.2

func Cycle[T any](a []T) Pipe[T]

func Func

func Func[T any](fn func(i int) (T, bool)) Pipe[T]

func FuncP

func FuncP[T any](fn func(i int) (*T, bool)) Pipe[T]

func Range

func Range[T constraints.Integer | constraints.Float](start, finish, step T) Pipe[T]

func Repeat added in v1.0.4

func Repeat[T any](x T, n int) Pipe[T]

func Slice

func Slice[T any](dt []T) Pipe[T]

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]) Count

func (p Pipe[T]) Count() int

Count evaluates all the pipeline and returns the amount of items.

func (Pipe[T]) Do

func (p Pipe[T]) Do() []T

Do evaluates all the pipeline and returns the result slice.

func (Pipe[T]) Erase added in v1.0.5

func (p Pipe[T]) Erase() Pipe[any]

func (Pipe[T]) Filter

func (p Pipe[T]) Filter(fn func(*T) bool) Pipe[T]

Filter leaves only items with true predicate fn.

func (Pipe[T]) First

func (p Pipe[T]) First() *T

func (Pipe[T]) Gen

func (p Pipe[T]) Gen(n int) Pipe[T]

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 (Pipe[T]) Map

func (p Pipe[T]) Map(fn func(T) T) Pipe[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 (Pipe[T]) MapFilter added in v1.0.5

func (p Pipe[T]) MapFilter(fn func(T) (T, bool)) Pipe[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 (Pipe[T]) Parallel

func (p Pipe[T]) Parallel(n uint16) Pipe[T]

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

func (p Pipe[T]) Promices() []func() (T, bool)

func (Pipe[T]) Reduce

func (p Pipe[T]) Reduce(fn AccumFn[T]) *T

Reduce applies the result of a function to each element one-by-one: f(p[n], f(p[n-1], f(p[n-2, ...]))).

func (Pipe[T]) Snag added in v1.0.5

func (p Pipe[T]) Snag(h ErrHandler) Pipe[T]

Sang ads error handler to a current Pipe step.

func (Pipe[T]) Sort

func (p Pipe[T]) Sort(less func(*T, *T) bool) Pipe[T]

Sort sorts the underlying slice on a current step of a pipeline.

func (Pipe[T]) Sum

func (p Pipe[T]) Sum(plus AccumFn[T]) T

Sum returns the sum of all elements. It is similar to Reduce but is able to work in parallel.

func (Pipe[T]) Take

func (p Pipe[T]) Take(n int) Pipe[T]

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 (Pipe[T]) Yeti added in v1.0.5

func (p Pipe[T]) Yeti(y YeetSnag) Pipe[T]

Yeti adds Yeti error handler to the pipe. If some other handlers were set before, they are handled by the Snag

type YeetSnag added in v1.0.5

type YeetSnag interface {
	// yeet an error
	Yeet(err error)
	// snag and handle the error
	Snag(ErrHandler)
}

type Yeti added in v1.0.5

type Yeti struct {
	// contains filtered or unexported fields
}

func NewYeti added in v1.0.5

func NewYeti() *Yeti

func (*Yeti) AddYeti added in v1.0.5

func (y *Yeti) AddYeti(yt yeti)

func (*Yeti) Handle added in v1.0.5

func (y *Yeti) Handle()

func (*Yeti) Snag added in v1.0.5

func (y *Yeti) Snag(handler ErrHandler)

func (*Yeti) Yeet added in v1.0.5

func (y *Yeti) Yeet(err error)

Jump to

Keyboard shortcuts

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