Skip to content

Instantly share code, notes, and snippets.

@creativedrewy
Created January 11, 2019 22:16
Show Gist options
  • Save creativedrewy/866675001899669926e3ba6f2f843b41 to your computer and use it in GitHub Desktop.
Save creativedrewy/866675001899669926e3ba6f2f843b41 to your computer and use it in GitHub Desktop.
/**
* Execute a lambda with two verified non-null values
*/
inline fun <T : Any, U : Any, W : Any> Pair<T?, U?>.bothNotNull(block: (one: T, two: U) -> W) {
first?.let { one ->
second?.let { two ->
block(one, two)
}
}
}
/**
* Execute a lambda with three verified non-null values
*/
inline fun <T : Any, U : Any, V : Any, W : Any> Triple<T?, U?, V?>.allNotNull(block: (one: T, two: U, three: V) -> W) {
first?.let { one ->
second?.let { two ->
third?.let { three ->
block(one, two, three)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment