Does it make huge difference between these two ver...
# android
c
Does it make huge difference between these two version ?
Copy code
displayCardList.filter { it.targetGrades?.contains(userGrade) == true }.run {
    return this.toMutableList().also {
        it.add(
            AmbientCardInfo(
                id = System.currentTimeMillis().toString(),
                cardType = CardType.GREETING.value,
                targetGrades = String.EMPTY
            )
        )
    }
}
V/S
Copy code
return displayCardList
      .filter { it.targetGrades?.contains(userGrade) == true }
      .toMutableList()
      .also { 
          it.add(
                            AmbientCardInfo(
                                id = System.currentTimeMillis().toString(),
                                cardType = CardType.GREETING.value,
                                targetGrades = String.EMPTY
                            )
                        )
       }
l
The biggest difference seems to be readability.
Copy code
val ambientCardInfo = AmbientCardInfo(
    id = System.currentTimeMillis().toString(),
    cardType = CardType.GREETING.value,
    targetGrades = String.EMPTY
)

return displayCardList
      .filter { it.targetGrades?.contains(userGrade) == true }
      .toMutableList()
      .also { it.add(ambientCardInfo) }
👍 1