在GO 1.18 generics
func pipe [a,t1,t2 any](左func(a)T1,right func(t1)t2)func(a)t2 { 返回func(a a)t2 { 返回右(左(a)) } } func openfile(名稱字符串) *os.file { ... } func readall(rdr io.reader)[] byte { ... } var openRead = pipe(openfile,readall)是一個錯誤?
Workaround
To address this limitation, a modified version of the Pipe function can be used, but it sacrifices compile-time type safety:
func Pipe[A, T1, T2, T3 any](left func(A) T1, right func(T2)T3)func(a)t3 { 返回func(a a)t3 { 返回右(任何(左(a))。(t2)) } }免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3