Create non-variadic functions without existingType using reflection

79 views
Skip to first unread message

Ankit Gupta

unread,
Dec 20, 2021, 4:07:32 PM12/20/21
to golang-nuts
Hey Folks, 

If I have argument type for a function: is it possible to create a function with those? 
Note: 
- we don't have reflect type for the function to be created so makeFunc can not be simply used.
- function inputTypes can differ so variadic can not be leveraged here.
- number of inputs can differ.

eg:
input arg types: TypeA, TypeB
expected output: func(TypeA, TypeB)

-----
Also, if it makes thing easier: Base problem which I have is:

input: func(inputTypes) (outputTypes)
expectedOutput: func(inputTypes)

Thanks!

Ian Lance Taylor

unread,
Dec 20, 2021, 4:27:12 PM12/20/21
to Ankit Gupta, golang-nuts
Use https://pkg.go.dev/reflect#FuncOf to get the type to pass to MakeFunc.

Ian
Reply all
Reply to author
Forward
0 new messages