2017-12-29 43 views
-1

ラムダ式を使用して次のように書くことができます.GO言語でこれをどのように達成できますか?基本的には、いくつかのパラメータを関数の前に渡し、いくつかのパラメータを後で利用できるようにする機能を探しています。GO言語のラムダ式

myFunc = (x) => Test(123, x) // Method Test is declared below. 
myFunc("hello") // this calls method Test with params int 123 & string "hello" where int was passed upfront whereas string was passed when Test is actually called on this line 

void Test(int n, string x) 
{ 
    // ... 
} 
+3

私はこの質問には[こちら](回答されていると思いますhttps://stackoverflow.com/questions/11766320/does-go-have-ラムダ式 - または何でも似たもの)。 –

答えて

3

はこれを試してみてください。

func Test(n int, x string) { 
    fmt.Println(n, x) 
} 
func main() { 
    myFunc := func(x string) { Test(123, x) } 
    myFunc("hello") 
} 

playground