operator

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package operator provides the small predicate expression language.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BindingEvaluator added in v0.24.0

type BindingEvaluator = expr.BindingEvaluator

BindingEvaluator provides the relationship between an evaluator and the evaluation context.

type Evaluator

type Evaluator = expr.Evaluator

Evaluator provides the evaluation function for an expression operator.

func And

func And(left, right Evaluator) Evaluator

And creates an evaluator that performs explicit logical AND with short-circuit evaluation. The evaluator implements the explicit logical AND operator. Both evaluators must yield for the result to be yielded. The right evaluator is only evaluated if the left evaluator yields (short-circuit evaluation). The expression pipeline already provides implicit AND semantics through juxtaposition, but this evaluator can be used for explicit AND operations.

func Compile added in v0.24.0

func Compile(items []BindingEvaluator) (Evaluator, error)

Compile provides a compiler for an expression which interprets the operators ( ) ! -and -or, which are parsed when the expression has the option expr.ParseOperators. Operators are converted to Not, And, and Or. Sub-expressions which use Predicate, PredicateContext, or Invariant as the evaluator are used directly. Any other evaluator is lifted into a sub-expression which is true when the evaluator yields and false otherwise; in either case, the input value (rather than the value that was yielded) continues through the pipeline. When no binary operator occurs between sub-expressions, -and is implied. The usual precedence applies: ! binds tightest, then -and, then -or.

An error is returned when the operators are not well-formed, such as a binary operator without a left or right operand, an unmatched parenthesis, or empty parentheses. When there are no binding evaluators, the resulting evaluator yields every value.

func Lift added in v0.24.0

func Lift(e Evaluator) Evaluator

Lift converts an evaluator into a sub-expression which is true when the evaluator yields and false otherwise. The resulting evaluator yields the input value at most once.

func Not

func Not(evaluator Evaluator) Evaluator

Not creates an evaluator that inverts the evaluation result of the given evaluator. The evaluator implements the unary NOT operator. It inverts the evaluation result: if the wrapped evaluator yields a value, the evaluator does not yield; if the wrapped evaluator does not yield, the evaluator yields the input value.

func Or

func Or(left, right Evaluator) Evaluator

Or creates an evaluator that performs logical OR with short-circuit evaluation. It evaluates the left evaluator first. If the left evaluator yields a value, the evaluator yields and does not evaluate the right evaluator. If the left evaluator does not yield, the right evaluator is evaluated.

Jump to

Keyboard shortcuts

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