stream

package
v0.0.0-...-2627f95 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Processor

type Processor func(Stream) Stream

Processor is a function that returns a stream derived from a source stream.

func Filter

func Filter(filter func(value interface{}) bool) Processor

Filter filters out elements from the source stream for which the filter function retruns false

func Limit

func Limit(limit int) Processor

Limit limits the number of streamed elements If limit <= 0 then there is no limit, it will return all elements from the source stream. Otherwise it will only return up to the first limit elements.

func Log

func Log(logger *zap.Logger) Processor

Log logs values as they pass through.

func Sort

func Sort(compare func(a interface{}, b interface{}) int, limit int) Processor

Sort finds the lowest N elements in a stream as defined by the comparison function and returns them in ascending order. If limit > 0 then N = limit, otherwise N = the size of the stream. In other words, if limit is <= 0 then it sorts the entire collection.

type Stream

type Stream interface {
	// Next advances the stream. It must
	// be called once at the start to advance
	// to the first item in the stream. It returns
	// true if there is a value available
	// or false otherwise. It may return false in
	// case of an error. Error() will return
	// an error if this is the case and must be checked
	// after Next() returns false.
	Next() bool
	// Value returns the value at the current position
	// or nil if iteration is done.
	Value() interface{}
	// Error returns the error that occurred, if any
	Error() error
}

Stream describes a stream of values

func Pipeline

func Pipeline(stream Stream, processors ...Processor) Stream

Pipeline connects a series of processors to a source stream and returns the derived stream. Pipeline can be useful to create code that is more readable than simply invoking processor functions in a nested way like this processor3(processor2(processor1(stream)))

Jump to

Keyboard shortcuts

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