Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotAFunction is returned when the type is not a function. ErrNotAFunction = errors.New("type is not a function") // ErrNotAStruct is returned when the type is not a struct. ErrNotAStruct = errors.New("type is not a struct") // ErrWrongNumArgs is returned when the number of arguments is wrong. ErrWrongNumArgs = errors.New("wrong number of arguments") // ErrInvalidArgType is returned when an argument type is invalid. ErrInvalidArgType = errors.New("invalid argument type") // ArgValueIsZeroErrMsg is the error message for an invalid argument value. ArgValueIsZeroErrMsg = "invalid argument value for type %s: got zero value" )
Functions ¶
func GetFunctionName ¶
GetFunctionName returns the name of the function.
Types ¶
type Arg ¶
type Func ¶
type Func struct { // Name is the name of the function. // It is formatted as "package.functionName". Name string // Args is the argument types of the function. Args []*Arg // Ret is a mapping of return types to values of the function. Ret map[Type]Value // IsVariadic is true if the function is variadic. IsVariadic bool // HasError is true if the function returns an error. HasError bool // contains filtered or unexported fields }
A Func is a wrapper around a reflect function value that provides convenience functions to get metadata and execute a function.
func MakeNamedFunc ¶
MakeNamedFunc creates a new Func instance from the given argument and return values. It generates a function which when called consumes the specified args and returns the given return values. It assigns this function a name which is formatted as "GeneratedFuncArgs{argTypes...}Ret{retTypes...}".
type StructType ¶
type StructType struct { Name string Type Type // Fields is a mapping of field types to their indices. Fields *utils.OrderedMap[Type, int] }
func NewStruct ¶
func NewStruct(s any) (*StructType, error)
func (*StructType) Constructor ¶
func (s *StructType) Constructor() *Func
Constructor returns a function that constructs a new instance of the struct.
func (*StructType) Provider ¶
func (s *StructType) Provider() *Func
Provider returns a function that takes in an instance of the struct and returns the value of each field as output.
Click to show internal directories.
Click to hide internal directories.