0

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)
{
    // ...
}
Azeem
  • 7,659
  • 4
  • 22
  • 36
aamir
  • 47
  • 1
  • 6
  • 3
    I think this question has been answered [here](https://stackoverflow.com/questions/11766320/does-go-have-lambda-expressions-or-anything-similiar). – newbie master Dec 29 '17 at 08:32

1 Answers1

4

try this :

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

playground

fzerorubigd
  • 1,473
  • 2
  • 15
  • 23