Tuang
05/22/2020, 9:46 AMfun A(infoA: Info, conn: Connection, userId: Int): Result {
val overSettingOfA: OverSetting = AppSetting.instance.retrieveA(infoA, conn, userId)
// some code
return Result(overSettingOfA)
}
fun B(infoB: Info, conn: Connection, userId: Int, someInfo: SomeInfo): Result {
val overSettingOfB: OverSetting = AppSetting.instance.retrieveB(infoB, userId, conn, someInfo)
// some code
return Result(overSettingOfB)
}
Both of fun A and fun B have the same logic, what they are doing is all the same. I m trying to do likes high order function but the problem is
the argument is not the same, fun A has 3 arg and fun B has 4.
Is there any a magical way? 😀Milan Hruban
05/22/2020, 9:49 AMTuang
05/22/2020, 9:49 AMBornyls Deen
05/22/2020, 10:02 AMA and retrieveA accept someInfo as an optional/nullable parameter?Bornyls Deen
05/22/2020, 10:02 AMretrieveA and retrieveB are duplicated in a similar way as `A`/`B` here.Tuang
05/22/2020, 10:05 AMCouldunfortunately No. because whatandAacceptretrieveAas an optional/nullable parameter?someInfo
retrieveA and retrieveB doing is not the same, i means they are doing different thingsTuang
05/22/2020, 10:06 AMBornyls Deen
05/22/2020, 10:06 AMfun A(infoA: Info, conn: Connection, userId: Int, someInfo: SomeInfo? = null): Result {
return if (someInfo == null) {
Result(AppSetting.instance.retrieveA(infoA, conn, userId))
} else {
Result(AppSetting.instance.retrieveB(infoA, conn, userId, someInfo))
}
}Bornyls Deen
05/22/2020, 10:06 AMTuang
05/22/2020, 10:08 AMBornyls Deen
05/22/2020, 10:09 AMSomeInfo being present/missing though in a similar way if it is under your control 😄Tuang
05/22/2020, 10:10 AMBornyls Deen
05/22/2020, 10:12 AM