Last active
July 17, 2018 14:25
-
-
Save luangs7/cc26412335c949c467f2c7294be66037 to your computer and use it in GitHub Desktop.
An example of creating a Swift like guard let extension function in Kotlin for EditText viewgroup
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 infix fun EditText.guard(call: () -> Unit): String? { | |
if (this.text.isNotEmpty()) return text | |
else { | |
call() | |
return null | |
} | |
} | |
//example of usage | |
val name = field.guard{ | |
println("This field cant be empty!") | |
return null | |
} | |
println($name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment