I have a function like this and it returns the ENUM data.
if (shouldShowCTA) {
if (progress) {
when (type) {
TYPE1 -> TYPE1_PROGRESS
TYPE2 -> TYPE2_PROGRESS
else -> null
}
} else if (completed) {
when (type) {
TYPE1 -> TYPE1_COMPLETED
TYPE2 -> TYPE2_COMPLETED
else -> null
}
} else {
null
}
} else {
null
}
Here I have a repeated code of When condition. How can I combine all the if and else if at one condition?