t
image.png
z
Your
keyedFunctions
map should have the type
Map<String, CalcContext.() -> Unit>
. Might be helpful to define a typealias for that function type.
t
Thanks Zach. Problem is though that Receiver needs to be generic. I tried making it generic and it compiles, but this causes another problem for me as in the actual code that uses the DSL now can't compile.
Reason being is because the contexts can have different method & properties exposed on them.
In other words. I can do this...
image.png
But then in my DSL code, it can't compile because it doesn't like those generic receivers (e.g. "T"). Because T (e.g. Context) doesn't really share any common methods & properties.
Basically, I'm trying to see if there's a way just to treat this as a function reference without compiler having to deal with binding it to a receiver when I store the function reference in the map.
z
Not sure I understand - I can't see in your initial code screenshot because the error popup is covering it, but what's the code for the
validation
method?
Oh I think I get it. So your map value type needs to be generic (
Any.() -> Unit
), and then you need to cast your
callback
arguments to that type when storing them in the map. Does that work?
t
I think I tried that as well
I might need to just rethink what I'm doing. 🙂
I'm probably in a bit of a tangle now.
Zach. The Any worked.
Thaks man!
I just had to clean up few other things that was causing another problem.
👍 1