Hmm, imho regarding your third code snippet, the syntax is obvious
Because { } is an object of () → (Unit) type, and you don’t use it in an assignment or expression, but in an invocation, you must invoke the lambda object.
why you just don’t if (someData!=null) {} else {}. Looks more clean.
Well, less verbose doesn’t always mean more clean or readable.
I stopped using run and apply in my code because modifying the meaning of this turned out to be a bad idea in some cases, because it increases ambiguity.
Example: something.run { x=y } — when i write the code I knew that x is from something and y is from the parent object or the method’s scope… but after a while this code gets confusing and way less readable, resulting in bugs that are not easy to detect during a quick read.
I almost always use something?.let{something → } and if(…)… even if I write more code, it’s more readable.
I also use run, apply, but only when it’s highly needed
Good point. Kotlin gives so many possibilities (except ternary operator), which can lead to unreadable code. Hard to find a balance That should come with experience.