--

To add to my previous reply. My own examples show one of the pitfalls of scope operators:

openFile(name)

?.run { processFile(this) }

?: handleFileError(name)

The elvis expression is executed if the previous operator returns null so if the expression in the run lambda returns null, it would execute both processFile and handleFileError. The correct code is:

openFile(name)

?.apply { processFile(this) }

?: handleFileError(name)

--

--