Skip to content

Instantly share code, notes, and snippets.

@aweiland
Created June 13, 2019 23:46
Show Gist options
  • Save aweiland/fbb2ea4374dfa121ed23ca4bb83f164c to your computer and use it in GitHub Desktop.
Save aweiland/fbb2ea4374dfa121ed23ca4bb83f164c to your computer and use it in GitHub Desktop.
Plural let
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