Created
January 11, 2019 22:16
-
-
Save creativedrewy/866675001899669926e3ba6f2f843b41 to your computer and use it in GitHub Desktop.
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
/** | |
* 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