This is probably not ideal… open to any feedback `...
# codereview
t
This is probably not ideal… open to any feedback
Copy code
sharedElements?.let { thisSharedElements -> 
  names?.let { thisNames ->
    viewHolder?.let { thisViewHolder ->
      thisSharedElements[thisNames[0]] = thisViewHolder.itemView
    }
  }
}
p
Why not just this?
Copy code
if (sharedElements != null
		&& names != null
		&& viewHolder != null) {
    sharedElements[names[0]] = viewHolder.itemView
}
If you do this often, then I would recommend to add extension function to your
sharedElements
to hide this code and call it like this:
Copy code
sharedElements?.setElement(names, viewHolder)
It depends on details of your real usages.
t
Thanks
Why not just this?
These are “platform” types in Android, so they are not
val
. I can do that, but would need to assign them all to `val`s first
so using the nested
?.let {...}
would be fewer lines of code
but ugly 🙂
p
I see… but it is more important for code to be readable than short 🙂
t
good point 👍
thanks for your feedback!
u
yea dont do that