Home >Backend Development >Golang >Golang generic + variable parameter function
In golang, there are some general types of functions
type transformer[a, b any] func(a)(b, error)
How to define a general variable parameter higher-order function, which can usually be composed of a function like this
func Compose[A,B,C....N any](transformers... Transformer[A,B], Transformer[B,C]...Transformer[M,N]) Transformer[A,N]
In Go, universal variadic functions are not yet supported. However, you can achieve similar results by using variadic arguments and recursion.
The above is the detailed content of Golang generic + variable parameter function. For more information, please follow other related articles on the PHP Chinese website!