Put everything in a single `apply`?
# announcements
k
Put everything in a single
apply
?
👍 2
p
In that case, should i use apply or run ? with run :
Copy code
return httpUrlBuilder().run {
  addQueryParameter(PARAMETER_CARD_ID, param.cardId)
  if (param.promoCode.isBlank().not()) {
    addQueryParameter(PARAMETER_PROMOCODE, param.promoCode)
  }
  build()
}
with apply :
Copy code
return httpUrlBuilder().apply {
  addQueryParameter(PARAMETER_CARD_ID, param.cardId)
  if (param.promoCode.isBlank().not()) {
    addQueryParameter(PARAMETER_PROMOCODE, param.promoCode)
  }
}.build()
k
I'd argue that the
apply
version is clearer here, since there is a clear separation between the setting-up and the actual running.
It really doesn't matter much though.
p
yeah that's not a big deal but i just wanted to know if there is some "good practices" to write stuff like that
i went for the
apply()
👍 1
1 less line 😛
thx 😉