Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]
like image 694
404 Avatar asked Apr 09 '26 16:04

404


1 Answers

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

like image 129
NubDev Avatar answered Apr 11 '26 06:04

NubDev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!