Last active
August 3, 2019 21:32
-
-
Save corneil/65ddb06d44b9f34e97d761bb344330d3 to your computer and use it in GitHub Desktop.
Kotlin extension functions to provide logic in association with same behaviour as apply
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <T> T.ifApply(expression: Boolean, block: T.() -> Unit, otherwise: T.() -> Unit) : T { | |
return if(expression) { | |
this.apply(block) | |
} else { | |
this.apply(otherwise) | |
} | |
} | |
inline fun <T> T.ifApply(expression: Boolean, block: T.() -> Unit) : T { | |
if(expression) { | |
this.apply(block) | |
} | |
return this | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment