package operators

import "github.com/purpleidea/mgmt/lang/funcs/operators"

Package operators provides a helper library to load all of the built-in operators, which are actually just functions.

Index

Constants

const (
	// OperatorFuncName is the name this function is registered as. This
	// starts with an underscore so that it cannot be used from the lexer.
	OperatorFuncName = "_operator"
)

Variables

var OperatorFuncs = make(map[string]*simple.Scaffold) // must initialize

OperatorFuncs maps an operator to a list of callable function values.

Functions

func LookupOperator

func LookupOperator(operator string, size int) (*types.Type, error)

LookupOperator returns the type for the operator you looked up. It errors if it doesn't exist, or if the arg length isn't equal to size.

func RegisterOperator

func RegisterOperator(operator string, scaffold *simple.Scaffold)

RegisterOperator registers the given string operator and function value implementation with the mini-database for this generalized, static, polymorphic operator implementation.

Types

type OperatorFunc

type OperatorFunc struct {
	*docsUtil.Metadata

	Type *types.Type // Kind == Function, including operator arg
	// contains filtered or unexported fields
}

OperatorFunc is an operator function that performs an operation on N values. XXX: Can we wrap SimpleFunc instead of having the boilerplate here ourselves?

func (*OperatorFunc) ArgGen

func (obj *OperatorFunc) ArgGen(index int) (string, error)

ArgGen returns the Nth arg name for this function.

func (*OperatorFunc) Build

func (obj *OperatorFunc) Build(typ *types.Type) (*types.Type, error)

Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.

func (*OperatorFunc) Call

func (obj *OperatorFunc) Call(ctx context.Context, args []types.Value) (types.Value, error)

Call this function with the input args and return the value if it is possible to do so at this time.

func (*OperatorFunc) FuncInfer

func (obj *OperatorFunc) FuncInfer(partialType *types.Type, partialValues []types.Value) (*types.Type, []*interfaces.UnificationInvariant, error)

FuncInfer takes partial type and value information from the call site of this function so that it can build an appropriate type signature for it. The type signature may include unification variables.

func (*OperatorFunc) Info

func (obj *OperatorFunc) Info() *interfaces.Info

Info returns some static info about itself. Build must be called before this will return correct data.

func (*OperatorFunc) Init

func (obj *OperatorFunc) Init(init *interfaces.Init) error

Init runs some startup code for this function.

func (*OperatorFunc) Stream

func (obj *OperatorFunc) Stream(ctx context.Context) error

Stream returns the changing values that this func has over time.

func (*OperatorFunc) String

func (obj *OperatorFunc) String() string

String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.

func (*OperatorFunc) Validate

func (obj *OperatorFunc) Validate() error

Validate tells us if the input struct takes a valid form.

Source Files

operators.go

Version
v0.0.0-20250322185616-c50a578426f1 (latest)
Published
Mar 22, 2025
Platform
linux/amd64
Imports
10 packages
Last checked
5 days ago

Tools for package owners.