mardi 12 février 2019

Can I convert a Kotlin KFunction1 to a KFunction0 by applying the argument?

I have a reference to a functionthat needs a parameter.

fun foo(x: Int) = 2 * x
val f: KFunction1<Int, Int> = ::foo

Is there any way to write applyArgument where

val f2: KFunction0<Int> = f1.applyArgument(42) 
assertEquals("foo", f2.name)
assertEquals(84, f2())

I don't want to use a callable reference, as I need access to the name property.





Aucun commentaire:

Enregistrer un commentaire