Skip to content

Instantly share code, notes, and snippets.

@luangs7
Last active July 17, 2018 14:25
Show Gist options
  • Select an option

  • Save luangs7/cc26412335c949c467f2c7294be66037 to your computer and use it in GitHub Desktop.

Select an option

Save luangs7/cc26412335c949c467f2c7294be66037 to your computer and use it in GitHub Desktop.

Revisions

  1. luangs7 revised this gist Jul 17, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion GuardLetEditTextExtension.kt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    inline infix fun EditText.guard(call: () -> Unit): String? {
    if (!this.text.isNotEmpty()) return text
    if (this.text.isNotEmpty()) return text
    else {
    call()
    return null
  2. luangs7 revised this gist Jul 17, 2018. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions GuardLetEditTextExtension.kt
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,6 @@ inline infix fun EditText.guard(call: () -> Unit): String? {
    call()
    return null
    }

    }


    @@ -14,5 +13,4 @@ val name = field.guard{
    println("This field cant be empty!")
    return null
    }

    println($name)
  3. luangs7 created this gist Jun 18, 2018.
    18 changes: 18 additions & 0 deletions GuardLetEditTextExtension.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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)