Can kotlin have function to do this?
# getting-started
c
Can kotlin have function to do this?
d
Kotlin has
if
.
đŸ’¯ 3
l
Considering your previous post, maybe you are searching for
.takeIf{}
c
@Dominaezzz you are right maybe I can just do
if(needRun) {println("it run")}
. I think too much
m
to get that exact syntax you could write an extension function on
Boolean
but yeah, would be overkill in this case
c
yes I was think about extension function, but using if would be the same it is still one expression code
@Luke that’s not my case
m
Copy code
inline fun Boolean.runIfTrue(action: () -> Unit) {
    if (this) action() 
}