Created
January 10, 2018 21:17
-
-
Save luisburgos/1510ad0bfbab23d65f4a14f30736b67f to your computer and use it in GitHub Desktop.
NullValidations
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
/** | |
* Multiple variable safety definitions | |
*/ | |
fun <T1: Any, T2: Any, R: Any> safeLet(p1: T1?, p2: T2?, block: (T1, T2)->R?): R? { | |
return if (p1 != null && p2 != null) block(p1, p2) else null | |
} | |
fun <T1: Any, T2: Any, T3: Any, R: Any> safeLet(p1: T1?, p2: T2?, p3: T3?, block: (T1, T2, T3)->R?): R? { | |
return if (p1 != null && p2 != null && p3 != null) block(p1, p2, p3) else null | |
} | |
fun <T1: Any, T2: Any, T3: Any, T4: Any, R: Any> safeLet(p1: T1?, p2: T2?, p3: T3?, p4: T4?, block: (T1, T2, T3, T4)->R?): R? { | |
return if (p1 != null && p2 != null && p3 != null && p4 != null) block(p1, p2, p3, p4) else null | |
} | |
fun <T1: Any, T2: Any, T3: Any, T4: Any, T5: Any, R: Any> safeLet(p1: T1?, p2: T2?, p3: T3?, p4: T4?, p5: T5?, block: (T1, T2, T3, T4, T5)->R?): R? { | |
return if (p1 != null && p2 != null && p3 != null && p4 != null && p5 != null) block(p1, p2, p3, p4, p5) else null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment