Created
June 13, 2019 23:46
-
-
Save aweiland/fbb2ea4374dfa121ed23ca4bb83f164c to your computer and use it in GitHub Desktop.
Plural let
This file contains hidden or 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
fun <T1: Any, T2: Any, R: Any> lets(first: T1?, second: T2?, block: (T1, T2)-> R?): R? { | |
return if (first != null && second != null) block(first, second) else null | |
} | |
fun <T1: Any, T2: Any, T3: Any, R: Any> lets(first: T1?, second: T2?, third: T3?, block: (T1, T2, T3)-> R?): R? { | |
return if (first != null && second != null && third != null) block(first, second, third) else null | |
} | |
fun <T1: Any, T2: Any, T3: Any, T4: Any, R: Any> lets(first: T1?, second: T2?, third: T3?, fourth: T4?, block: (T1, T2, T3, T4)-> R?): R? { | |
return if (first != null && second != null && third != null && fourth != null) block(first, second, third, fourth) else null | |
} | |
lets(userLoginForm.email, userLoginForm.password) { email, password -> | |
// email and password guaranteed to not be null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment