Documentation ¶
Index ¶
- Variables
- func Finish(fns ...func() error) error
- func FinishVoid(fns ...func())
- func ForEach[T any](generate GenerateFunc[T], mapper ForEachFunc[T], opts ...Option)
- func MapReduce[T, U, V any](generate GenerateFunc[T], mapper MapperFunc[T, U], reducer ReducerFunc[U, V], ...) (V, error)
- func MapReduceChan[T, U, V any](source <-chan T, mapper MapperFunc[T, U], reducer ReducerFunc[U, V], ...) (V, error)
- func MapReduceVoid[T, U any](generate GenerateFunc[T], mapper MapperFunc[T, U], reducer VoidReducerFunc[U], ...) error
- type ForEachFunc
- type GenerateFunc
- type MapFunc
- type MapperFunc
- type Option
- type ReducerFunc
- type VoidReducerFunc
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCancelWithNil is an error that mapreduce was cancelled with nil. ErrCancelWithNil = errors.New("mapreduce cancelled with nil") // ErrReduceNoOutput is an error that reduce did not output a value. ErrReduceNoOutput = errors.New("reduce not writing value") )
Functions ¶
func ForEach ¶
func ForEach[T any](generate GenerateFunc[T], mapper ForEachFunc[T], opts ...Option)
ForEach maps all elements from given generate but no output.
func MapReduce ¶
func MapReduce[T, U, V any](generate GenerateFunc[T], mapper MapperFunc[T, U], reducer ReducerFunc[U, V], opts ...Option) (V, error)
MapReduce maps all elements generated from given generate func, and reduces the output elements with given reducer.
func MapReduceChan ¶
func MapReduceChan[T, U, V any](source <-chan T, mapper MapperFunc[T, U], reducer ReducerFunc[U, V], opts ...Option) (V, error)
MapReduceChan maps all elements from source, and reduce the output elements with given reducer.
func MapReduceVoid ¶
func MapReduceVoid[T, U any](generate GenerateFunc[T], mapper MapperFunc[T, U], reducer VoidReducerFunc[U], opts ...Option) error
MapReduceVoid maps all elements generated from given generate, and reduce the output elements with given reducer.
Types ¶
type ForEachFunc ¶
type ForEachFunc[T any] func(item T)
ForEachFunc is used to do element processing, but no output.
type GenerateFunc ¶
type GenerateFunc[T any] func(source chan<- T)
GenerateFunc is used to let callers send elements into source.
type MapFunc ¶
type MapFunc[T, U any] func(item T, writer Writer[U])
MapFunc is used to do element processing and write the output to writer.
type MapperFunc ¶
MapperFunc is used to do element processing and write the output to writer, use cancel func to cancel the processing.
type Option ¶
type Option func(opts *mapReduceOptions)
Option defines the method to customize the mapreduce.
func WithContext ¶
WithContext customizes a mapreduce processing accepts a given ctx.
func WithWorkers ¶
func WithWorkers(workers int) Option
WithWorkers customizes a mapreduce processing with given workers.
type ReducerFunc ¶
ReducerFunc is used to reduce all the mapping output and write to writer, use cancel func to cancel the processing.
type VoidReducerFunc ¶
VoidReducerFunc is used to reduce all the mapping output, but no output. Use cancel func to cancel the processing.