I am working with kotlin and functional programming to develop an api.I really could not figure out whether did i break any FP rules here by using here. I have a following function which gives me customerNumber and bunch of other fields.
data class CustomerInfo(val customerNumber:String?=null,val accountNumber:String?=null,val email:String?=null)
and I have function with lot of conditions but conditions are same for all fields
fun getCustomerInfo(someDto:SomeDto,someOtherDto:SomeOtherDto,oneMoreDto:OneMoreDto):CustomerInfo
{
var customerNumber = someDto.id
var accountNo = someDto.accountNumber
var email = someDto.email
if(someCondition())
{
customerNumber= someOtherDto.id
accountNo = someOtherDto.accountNo
email = someOtherDto.email
}else if(someOtherConditiion)
{
customerNumber= oneMoreDto.id
accountNo = oneMoreDto.accountNo
email = oneMoreDto.email
}
//and many more conditions like this
return CustomerInfo(customerNumber,accountNo,email)
}
Is using var inside a functions is wrong?How can write this function without using var's here ? I know i can return the dto every-time directly once the condition met,but i feel like using same dto in 10 conditions?Any help would be appreciated
SomeDtoandSomeOtherDtoetc, are all different types, but having the exact same properties asCustomerInfo?