Does this function already exist in the stdlib or ...
# announcements
m
Does this function already exist in the stdlib or widely used package? :
Copy code
fun <T, R> T.runIf(condition: Boolean, f: T.() -> R): R? {
    return if (condition) { f() } else { null }
}
It behaves a bit like
run
from the stdlib, but applies the extension function conditionally, producing a nullable result.