sourcecode icon indicating copy to clipboard operation
sourcecode copied to clipboard

Cannot get lambda code passed to a function using sourcecode.Args

Open lokifacio opened this issue 6 years ago • 0 comments

Is there a way to get the source code of the lambda function passed to another function?

I get the expected result with basic types

def myBasicFunc(param: Int): String = {
 sourcecode.Args().head.head.toString
}

myBasicFunc(4) // Text(4,param)

But when I try to use the same approach with lambda functions I only get the generic function1 value

def myLambdaFunc(param: Int => Int): String = {
 sourcecode.Args().head.head.toString
}

myLambdaFunc(x => x*2) // Text(<function1>,param)

Is this the expected behavior? Am I missing something?

lokifacio avatar Jan 19 '20 12:01 lokifacio