gogenericsvariadic

Golang Generic+Variadic Function


In Golang having a number of functions of some generic type

type Transformer[A, B any] func(A)(B, error)

How to define a Generic Variadic high order function that could compose such functions in general something as

func Compose[A,B,C....N any](transformers... Transformer[A,B], Transformer[B,C]...Transformer[M,N]) Transformer[A,N]

Solution

  • In Go, generic variadic functions are not yet supported. However, you can achieve a similar result by using variadic arguments and recursion.