dukat icon indicating copy to clipboard operation
dukat copied to clipboard

Generate builder functions for SAM like interfaces

Open bashor opened this issue 8 years ago • 2 comments

Examples:

external interface MyFunction {
    @nativeInvoke
    fun invoke(a: Int, b: String): Int
}

inline fun MyFunction(f: (a: Int, b: String) -> Int): MyFunction {
    return f.unsafeCast<MyFunction>()
}

external interface MyFunctionWithVararg {
    @nativeInvoke
    fun invoke(a: Int, vararg b: String): Int
}

inline fun MyFunction(f: (a: Int, b: String) -> Int): MyFunctionWithVararg {
    return { a -> f(a, js("arguments").slice(1)) }
}

bashor avatar Aug 04 '17 10:08 bashor

Covered in a proposal we have in "DUKAT-9. Light-weight builder for (presumably) config-like interfaces".

Schahen avatar May 29 '20 23:05 Schahen

Any update ?

Ayfri avatar Aug 26 '21 07:08 Ayfri