Did you know that only Kotlin JS cannot implement ...
# javascript
h
Did you know that only Kotlin JS cannot implement lambdas? I hope it becomes possible soon.
Copy code
class Some private constructor(val v:Any){
  companion object:(Any)->Some{
    override fun invoke(v:Any) = Some(v)
  }
}

fun <T, R> needFactory(v:T, factory:(T)->R):R = factory(v)

needFactory(3, Some)
Implementing lambda is one of the simplest ways to create a factory ^^
a
Maybe I am dumb, but what is the use of this code? Why not just do Some(3).
a
We try to use the native JS functions to not create a new object/class for each lambda/function. But you are right, we should definitely to fix it. Could you please create an issue on YouTrack?
e
@Arjan van Wieringen that's probably a simplified example. And it can make sense to want to pass a lambda to a function like
needFactory
I think the key point is the behavior of the language is different depending on the target, which is unexpected. To me it looks a good enhancement, the only thing, as Artem wrote, is I wouldn't like more overhead than what's necessary. That is, if a fix for this messes up something else, then better avoid.
h
sorry about wrong sample ^^