zapped the redundant getOrElse method as the ?: does indeed work with lazy expressions (no function definition required) - thanks for spotting this Andrey! :)

This commit is contained in:
James Strachan
2012-02-09 06:25:25 +00:00
parent 2dfb1fef0e
commit d604272744
2 changed files with 8 additions and 26 deletions
-11
View File
@@ -69,14 +69,3 @@ inline fun <T> Iterator<T>.toTreeSet() = to(TreeSet<T>())
Run function f
*/
inline fun <T> run(f: () -> T) = f()
/*
Allow a default value to be lazily provided from a function when converting a nullable type to a non-nullable type
*/
// TODO would be nice to replace this with the ?: notation instead allowing a function as an argument for the default :)
inline fun <T> T?.getOrElse(defaultValueFactory: ()-> T): T {
return if (this != null)
this
else
defaultValueFactory()
}