lang: interfaces, funcs: Implement fmt.Stringer for functions
This adds the requirement that all function implementations provider a String() string method so that these can be used as vertices in the pgraph library. If we eventually move to generics for the pgraph DAG, then this might not matter, but it's not bad that these have names either.
This commit is contained in:
@@ -26,6 +26,11 @@ import (
|
||||
"github.com/purpleidea/mgmt/util/errwrap"
|
||||
)
|
||||
|
||||
const (
|
||||
// FunctionFuncName is the unique name identifier for this function.
|
||||
FunctionFuncName = "function"
|
||||
)
|
||||
|
||||
// FunctionFunc is a function that passes through the function body it receives.
|
||||
type FunctionFunc struct {
|
||||
Type *types.Type // this is the type of the function that we hold
|
||||
@@ -40,6 +45,12 @@ type FunctionFunc struct {
|
||||
closeChan chan struct{}
|
||||
}
|
||||
|
||||
// String returns a simple name for this function. This is needed so this struct
|
||||
// can satisfy the pgraph.Vertex interface.
|
||||
func (obj *FunctionFunc) String() string {
|
||||
return FunctionFuncName
|
||||
}
|
||||
|
||||
// fn returns the function that wraps the Func interface if that API is used.
|
||||
func (obj *FunctionFunc) fn() (*types.FuncValue, error) {
|
||||
fn := func(args []types.Value) (types.Value, error) {
|
||||
|
||||
Reference in New Issue
Block a user