Skip to content

Instantly share code, notes, and snippets.

View luangs7's full-sized avatar
:shipit:
Working

Luan G S luangs7

:shipit:
Working
View GitHub Profile
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@luangs7
luangs7 / GuardLetKotlinExtension.kt
Last active August 15, 2018 15:31
An example of creating a Swift like guard let extension function in Kotlin with rule validation
inline infix fun EditText.guard(rule:Boolean,call: () -> Unit): String? {
if (this.text.isNotEmpty() && rule) return text
else {
call()
return null
}
}
fun String.isEmail(): Boolean {
val p = "^(\\w)+(\\.\\w+)*@(\\w)+((\\.\\w+)+)\$".toRegex()
@luangs7
luangs7 / GuardLetEditTextExtension.kt
Last active July 17, 2018 14:25
An example of creating a Swift like guard let extension function in Kotlin for EditText viewgroup
inline infix fun EditText.guard(call: () -> Unit): String? {
if (this.text.isNotEmpty()) return text
else {
call()
return null
}
}
//example of usage