package function import ( "fmt" "reflect" ) func invokeFunc(fn any, args ...any) []reflect.Value { fv := functionValue(fn) params := make([]reflect.Value, len(args)) for i, item := range args { params[i] = reflect.ValueOf(item) } return fv.Call(params) } func unsafeInvokeFunc(fn any, args ...any) []reflect.Value { fv := reflect.ValueOf(fn) params := make([]reflect.Value, len(args)) for i, item := range args { params[i] = reflect.ValueOf(item) } return fv.Call(params) } func functionValue(function any) reflect.Value { v := reflect.ValueOf(function) if v.Kind() != reflect.Func { panic(fmt.Sprintf("Invalid function type, value of type %T", function)) } return v } func mustBeFunction(function any) { v := reflect.ValueOf(function) if v.Kind() != reflect.Func { panic(fmt.Sprintf("Invalid function type, value of type %T", function)) } }