hi guys, i needs some review for my code. ``` f...
# codereview
t
hi guys, i needs some review for my code.
Copy code
fun 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? 😀
m
is the type of overSettingOfA and overSettingOfB same?
t
yeah they have the same type
b
Could
A
and
retrieveA
accept
someInfo
as an optional/nullable parameter?
Assuming
retrieveA
and
retrieveB
are duplicated in a similar way as `A`/`B` here.
t
@Bornyls Deen
Could 
A
 and 
retrieveA
 accept 
someInfo
 as an optional/nullable parameter?
unfortunately No. because what
retrieveA
and
retrieveB
doing is not the same, i means they are doing different things
that’s why the parameter is different
👍 1
b
Copy code
fun 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))
    }
}
👍 1
maybe something like this would work then
t
umm,,,not too bad idea 😀
b
Just a thought. It might be better to update the retrieve method to handle the case of
SomeInfo
being present/missing though in a similar way if it is under your control 😄
👍 1
t
yeah, i think so…. thanks
b
no problem 🙂