0
\$\begingroup\$

I'm mapping our Lead object (which is very messy) to a data object for the UI.

It takes a couple seconds to map 1000 objects, how can I improve the performance?

private suspend fun mapLeadToViewData(leadList: List<Lead>): List<AddLeadViewData> = withContext(Dispatchers.Default) {
            leadList.filter { it.address.latitude != null || it.address.longitude != null }
            .map {
                val name = if (it.businessName != null && it.businessName != "") it.businessName
                else if (it.primaryContact != null && it.primaryContact.fullName != null && it.primaryContact.fullName != "") it.primaryContact.fullName
                else it.status.name ?: ""
                AddLeadViewData(name, it.address.singleLineAddress()
                        ?: "", false, it.status.buttonDrawable, it.id!!, it.status.name, it.address.city, it.address.state, it.address.postalCode)
            }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.