stream

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidResult = errors.New("expression must evaluate to a document")

ErrInvalidResult is returned when an expression supposed to evaluate to a document returns something else.

View Source
var ErrStreamClosed = errors.New("stream closed")

ErrStreamClosed is used to indicate that a stream must be closed.

Functions

This section is empty.

Types

type BaseOperator added in v0.15.0

type BaseOperator struct {
	Prev Operator
	Next Operator
}

func (*BaseOperator) GetNext added in v0.15.0

func (op *BaseOperator) GetNext() Operator

func (*BaseOperator) GetPrev added in v0.15.0

func (op *BaseOperator) GetPrev() Operator

func (*BaseOperator) SetNext added in v0.15.0

func (op *BaseOperator) SetNext(o Operator)

func (*BaseOperator) SetPrev added in v0.15.0

func (op *BaseOperator) SetPrev(o Operator)

type ConcatOperator

type ConcatOperator struct {
	BaseOperator
	Streams []*Stream
}

A ConcatOperator concatenates two streams.

func Concat

func Concat(s ...*Stream) *ConcatOperator

Concat turns two individual streams into one.

func (*ConcatOperator) Iterate

func (*ConcatOperator) String

func (it *ConcatOperator) String() string

type DiscardOperator added in v0.15.0

type DiscardOperator struct {
	BaseOperator
}

DiscardOperator is an operator that doesn't do anything.

func Discard added in v0.15.0

func Discard() *DiscardOperator

Discard is an operator that doesn't produce any document. It iterates over the previous operator and discards all the documents.

func (*DiscardOperator) Iterate added in v0.15.0

func (op *DiscardOperator) Iterate(in *environment.Environment, _ func(out *environment.Environment) error) (err error)

Iterate iterates over all the streams and returns their union.

func (*DiscardOperator) String added in v0.15.0

func (it *DiscardOperator) String() string

type OnConflictOperator added in v0.15.0

type OnConflictOperator struct {
	BaseOperator

	OnConflict *Stream
}

OnConflictOperator handles any conflicts that occur during the iteration.

func OnConflict added in v0.15.0

func OnConflict(onConflict *Stream) *OnConflictOperator

func (*OnConflictOperator) Iterate added in v0.15.0

func (*OnConflictOperator) String added in v0.15.0

func (op *OnConflictOperator) String() string

type Operator

type Operator interface {
	Iterate(in *environment.Environment, fn func(out *environment.Environment) error) error
	SetPrev(prev Operator)
	SetNext(next Operator)
	GetNext() Operator
	GetPrev() Operator
	String() string
}

An Operator is used to modify a stream. It takes an environment containing the current value as well as any other metadata created by other operatorsand returns a new environment which will be passed to the next operator. If it returns a nil environment, the env will be ignored. If it returns an error, the stream will be interrupted and that error will bubble up and returned by this function, unless that error is ErrStreamClosed, in which case the Iterate method will stop the iteration and return nil. Stream operators can be reused, and thus, any state or side effect should be kept within the Op closure unless the nature of the operator prevents that.

func InsertAfter

func InsertAfter(op, newOp Operator) Operator

func InsertBefore

func InsertBefore(op, newOp Operator) Operator

func Pipe

func Pipe(ops ...Operator) Operator

type OperatorFunc

type OperatorFunc func(func(env *environment.Environment) error) error

An OperatorFunc is the function that will receive each value of the stream.

type Range added in v0.14.0

type Range struct {
	Min, Max expr.LiteralExprList
	Paths    []document.Path
	// Exclude Min and Max from the results.
	// By default, min and max are inclusive.
	// Exclusive and Exact cannot be set to true at the same time.
	Exclusive bool
	// Used to match an exact value equal to Min.
	// If set to true, Max will be ignored for comparison
	// and for determining the global upper bound.
	Exact bool
}

Range represents a range to select values after or before a given boundary.

func (*Range) Eval added in v0.14.0

func (r *Range) Eval(env *environment.Environment) (*database.Range, error)

func (*Range) IsEqual added in v0.14.0

func (r *Range) IsEqual(other *Range) bool

func (*Range) String added in v0.14.0

func (r *Range) String() string

type Ranges added in v0.14.0

type Ranges []Range

func (Ranges) Append added in v0.14.0

func (r Ranges) Append(rng Range) Ranges

Append rng to r and return the new slice. Duplicate ranges are ignored.

func (Ranges) Cost added in v0.14.0

func (r Ranges) Cost() int

Cost is a best effort function to determine the cost of a range lookup.

func (Ranges) Eval added in v0.14.0

func (r Ranges) Eval(env *environment.Environment) ([]*database.Range, error)

Encode each range using the given value encoder.

func (Ranges) String added in v0.14.0

func (r Ranges) String() string

type Stream

type Stream struct {
	Op Operator
}

func New

func New(op Operator) *Stream

func (*Stream) First

func (s *Stream) First() Operator

func (*Stream) Iterate

func (s *Stream) Iterate(in *environment.Environment, fn func(out *environment.Environment) error) error

func (*Stream) Pipe

func (s *Stream) Pipe(op Operator) *Stream

func (*Stream) Remove

func (s *Stream) Remove(op Operator)

func (*Stream) String

func (s *Stream) String() string

type UnionOperator added in v0.14.0

type UnionOperator struct {
	BaseOperator
	Streams []*Stream
}

UnionOperator is an operator that merges the results of multiple operators.

func Union added in v0.14.0

func Union(s ...*Stream) *UnionOperator

Union returns a new UnionOperator.

func (*UnionOperator) Iterate added in v0.14.0

func (it *UnionOperator) Iterate(in *environment.Environment, fn func(out *environment.Environment) error) (err error)

Iterate iterates over all the streams and returns their union.

func (*UnionOperator) String added in v0.14.0

func (it *UnionOperator) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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