ifOrNull
Checks condition, and if it is true, runs the block and returns its result. Returns null otherwise.
This is a shorthand for if (condition) { block() } else { null }.
Usage
This function is useful when a condition determines whether an action needs to be performed, with its result returned.
// If `shouldSendPopup` is `false`, `sendPopup` will not get called
val popup: Popup? = ifOrNull(shouldSendPopup) {
sendPopup()
}Content copied to clipboard