Don't you find yourself in a situation, when you s...
# codingconventions
g
Don't you find yourself in a situation, when you start writing
with
then realize that the type is nullable and fallback to
?.apply{}
? Relevant question on SO: https://stackoverflow.com/questions/35723226/how-to-use-kotlins-with-expression-for-nullable-types
g
I have been writing in Kotlin more than 3 years and almost never use
with
, only for nested contexts I just don’t see good use cases for it except context nesting (but in this case you usually don’t have nullability)
👆 2
g
After a closer look,
.run/?.run
seems to be the exact counterpart of
with
functionality
g
Yes, run has the same semantics
But apply also works if you don't need result or need receiver as expression result