Now I am working on some problems about passing the function as parameter in a function with vararg parameter with generic parameter. The below code works for one function as parameter into other
function like that funA(funB(parameter):return1):return2
but when i make function like that
funA(vararg funB(parameter):return1):return2
it doesn't works. I have tried somethings like Array or KFunction1
ViewModel
fun callMultipleAPI( vararg observable: Observable<Any>):LiveData<Boolean>{
.....
return progressDialogData!!
}
fun callGetTeammateListAPITEST():Observable<Any>{
....
return repo.callGetMessageSumTEST()!!
}
Fragment
fun test(){
EasyDialog<Observable<Any>,LiveData<Boolean>>(ctx, true,viewModel!!::callGetTeammateListAPITEST,recallFunctionWithFunction = viewModel!!::callMultipleAPI).createNativeNetworkDialog2()
}
EasyDialog
class EasyDialog<T,V> {
var canCancel: Boolean = true
var recallFunction: (() -> T)? = null
var recallFunctionWithValue: ((value: T) -> Unit)? = null
var context: Context? = null
var value: T? = null
var functionPara :(()->T)? = null
var recallFunctionWithFunction:((T) -> V)? = null
constructor(
context: Context?, canCancel: Boolean, value: ()->T, recallFunctionWithFunction: (T) -> V ){
this.context = context
this.canCancel = canCancel
this.functionPara = value
this.recallFunctionWithFunction = recallFunctionWithFunction
}
fun createNativeNetworkDialog2() {
...
functionPara?.let{ functionPara->{ recallFunctionWithFunction?.let {
recallFunctionWithFunction-> compose<T,V>(recallFunctionWithFunction ,functionPara).invoke()
}}}
}
}
fun <T, V> compose( f: (T) -> V, g:() -> T ): () -> V {
return { f(g()) }
}
But it only allow the function without vararg parameter. I try to make something out as below
var functionPara :(()->T)? = null
var recallFunctionWithFunction:( (Array<out T>) -> V)? = null
constructor(
context: Context?, canCancel: Boolean, value: ()->T, recallFunctionWithFunction: (Array<out T>) -> V ){
this.context = context
this.canCancel = canCancel
this.functionPara = value
this.recallFunctionWithFunction = recallFunctionWithFunction
}
fun <T, V> compose( f: (Array<out T>)->V, vararg g:() -> T ): () -> V {
return { f(g()) }
}
but it shows the type mismatch
can anyone help?
Aucun commentaire:
Enregistrer un commentaire