This question already has an answer here:
In C#, we can write something like following using lambda expression, how can we achieve this in GO language? Basically, I am looking for an ability to pass some params to the function upfront and some params later when they are available.
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)
{
// ...
}
</div>
try this :
func Test(n int, x string) {
fmt.Println(n, x)
}
func main() {
myFunc := func(x string) { Test(123, x) }
myFunc("hello")
}