is there a multi-platform way to check if a variab...
# announcements
r
is there a multi-platform way to check if a variable (of type
Any
) is a function/lambda?
v is Function<*>
works on JVM, but doesn't work on JS platform
g
Really curious why do you need to know that
1
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
kotlin.jvm.functions
. Actually now it looks like a bug, because check that type is functional type makes a lot of sense for me
r
https://github.com/reduxkotlin/redux-kotlin-thunk/blob/master/lib/src/commonMain/kotlin/org/reduxkotlin/Thunk.kt 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.
d
r
@dmitriy.novozhilov how does it help?
d
v is KFunction<*>
doesn't work?
r
no, it doesn't neither on JS nor JVM
g
@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