How to access the field 'arg' of a function argument in Scala

55 Views Asked by At

I have a function:

def func(f: Any => WrappedDataset): WrappedDataset = {
 // I would like to do something like `val expr = f.arg.expr` here
}

There is no such field on 'f' called arg. But when I put a breakpoint inside of func I can see that the field I need "expr" is there at runtime.

Inspecting the argument 'f' runtime

Is there some way, perhaps using scala reflect, that I can take the value inside of one of the arg fields and save to a variable inside of func() ?

1

There are 1 best solutions below

8
slouc On

Perhaps I misunderstand your question, but there's no such thing as "arg" as far as the body of func is concerned. There's only a function that can be applied to an argument of the defined type, in your case Any.

Think of it like this: someone gifts you a pasta maker. Raw pasta goes in, spaghetti come out. When you're handed this pasta maker, you can't say "okay let me look at the raw pasta". For now, all you have is a pasta maker (function), and later once you obtain some raw pasta (value of type Any), you will be able to apply it.

If you need to know the argument in the body of func(), then you need to make it a parameter:

def func(f: Any => WrappedDataset, arg: Any): WrappedDataset