第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用反射檢查分配給 interface{} 變量的函數(shù)簽名

使用反射檢查分配給 interface{} 變量的函數(shù)簽名

Go
Qyouu 2021-07-29 21:19:02
我正在嘗試構(gòu)建一個(gè) 通用的 咖喱 看起來像這樣的功能:package curryimport (    "fmt"    "reflect")// Functiontype fn interface{}// Function parametertype pr interface{}// It return the curried functionfunc It(f fn, p ...pr) (fn, error) {    // examine the concret type of the function f    if reflect.ValueOf(f).Kind() == reflect.Func {    // Get the slice of input and output parameters type     } else {        return nil, fmt.Errorf("%s", "takes a function as a first parameter")    }    // _, _ = f, p    return nil, nil}是否可以[]reflect.Type從函數(shù)中提取輸入和輸出參數(shù)類型的切片f?
查看完整描述

2 回答

?
開心每一天1111

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超13個(gè)贊

Go 1.5 將添加一個(gè)可以在這里提供幫助的功能。(回顧 1996 年,由Dave ( )提交 e1c1fa2)okdave


// FuncOf returns the function type with the given argument and result types.

// For example if k represents int and e represents string,

// FuncOf([]Type{k}, []Type{e}, false) represents func(int) string.

//

// The variadic argument controls whether the function is variadic. FuncOf

// panics if the in[len(in)-1] does not represent a slice and variadic is

// true.

func FuncOf(in, out []Type, variadic bool) Type

測(cè)試用例包括以下有趣的代碼:


v := MakeFunc(FuncOf([]Type{TypeOf(K(""))}, []Type{TypeOf(V(0))}, false), fn)

outs := v.Call([]Value{ValueOf(K("gopher"))})


查看完整回答
反對(duì) 回復(fù) 2021-08-02
  • 2 回答
  • 0 關(guān)注
  • 203 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)