is there a multi-platform way to check if a variab...
# announcements
is there a multi-platform way to check if a variable (of type
) is a function/lambda?
v is Function<*>
works on JVM, but doesn't work on JS platform
Really curious why do you need to know that
As I understand (tho it may be wrong), It works on JVM only because of implementation details of Kotlin lambda and method reference on JVM, so it’s more like implementation detail, so it doesn’t work for other platforms Nope, I was wrong, Function<*> should work, I thought it was
. Actually now it looks like a bug, because check that type is functional type makes a lot of sense for me
r This project uses this, but it doesn't work on JS, where I need it. I could try to repair this, but I don't now how to do it.
Probably just cast to function type could be enough. It works correctly on JS and JVM.
@dmitriy.novozhilov how does it help?
v is KFunction<*>
doesn't work?
no, it doesn't neither on JS nor JVM
@Robert Jaros Now I see, it’s really unfortunate. But by checking original code I don’t have enough confidence, but wouldn’t be better just check for Thunk type? I mean of course it may be some other functional type, but probably just propagate would be better, because now it essentially throws exception on any type with Function interface which doesn’t look correct