InlineOnly Result.getOrNull method

This commit is contained in:
Roman Elizarov
2018-09-13 23:24:27 +03:00
parent feb7239189
commit 4d3d376db8
2 changed files with 4 additions and 38 deletions
@@ -43,9 +43,10 @@ public inline class Result<out T> @PublishedApi internal constructor(
* This function is shorthand for `getOrElse { null }` (see [getOrElse]) or
* `fold(onSuccess = { it }, onFailure = { null })` (see [fold]).
*/
public fun getOrNull(): T? =
when (value) {
is Failure -> null
@InlineOnly
public inline fun getOrNull(): T? =
when {
isFailure -> null
else -> value as T
}