invocation

package
v0.0.0-...-e90178e Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package invocation provides a mechanism for defining and invoking functions in a yamlpath expression.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownFunc = errors.New("unknown function")
	ErrBadFunc     = errors.New("bad function")
	ErrBadArgument = errors.New("bad argument")
)

ErrUnknownFunc is an error that is returned when a function is not found in the function table.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

Entry is a function entry in the function table.

func (*Entry) Invoke

func (e *Entry) Invoke(params ...reflect.Value) (reflect.Value, error)

Invoke invokes the function with the given context and arguments.

func (*Entry) SetArity

func (e *Entry) SetArity(a arity.Arity)

SetArity sets the arity of the function entry.

func (*Entry) TestArity

func (e *Entry) TestArity(n int) error

TestArity tests the arity of the function with the given number of arguments.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is an invocation table that maps function names to function definitions.

func NewTable

func NewTable() *Table

NewTable creates a new function table.

func (*Table) Add

func (t *Table) Add(name string, fn funcEntry) *Entry

Add adds a function to the table. By default, functions have an arity of zero -- meaning no arguments may be provided to them. To set the arity of the function, use the Entry.SetArity method on the returned Entry.

func (*Table) AddFunc

func (t *Table) AddFunc(name string, fn any) error

AddFunc is a convenience method for adding a normal Go function to the function table. This will implicitly convert the function to a [funcEntry] and set the arity of the function based on the number of arguments and return values of the function. The function must have at least one return value, and at most two return values with the second return value being an [error] type.

func (*Table) FunctionNames

func (t *Table) FunctionNames() iter.Seq[string]

FunctionNames returns an iterator over the function names in the table. Names are not guaranteed to be unique if a parent table is used and the derived table shadows a function in the parent table.

func (*Table) Lookup

func (t *Table) Lookup(name string) (fn *Entry, ok bool)

Lookup performs a function lookup in the table, and if the function is not found, it will recursively search the parent table. If the function is not found in the parent table, ok will be set to false and fn will be nil.

func (*Table) New

func (t *Table) New() *Table

New creates a new function table from the current parent table.

Directories

Path Synopsis
Package arity is a micro-package for providing the Arity type, which is used to identify whether the number of arguments being provided to an invocation is valid.
Package arity is a micro-package for providing the Arity type, which is used to identify whether the number of arguments being provided to an invocation is valid.

Jump to

Keyboard shortcuts

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