Class NetworkResult
-
- All Implemented Interfaces:
-
java.io.Serializable
public final class NetworkResult<T extends Object> implements Serializable
A discriminated union that encapsulates a successful outcome with a value of type T or a failure with an arbitrary Throwable exception.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classNetworkResult.CompanionCompanion object for Result class that contains its constructor functions success and failure.
-
Method Summary
Modifier and Type Method Description final BooleanisSuccess()final BooleanisFailure()final TgetOrNull()Returns the encapsulated value if this instance represents success or nullif it is failure.final ThrowableexceptionOrNull()Returns the encapsulated Throwable exception if this instance represents failure or nullif it is success.StringtoString()Returns a string Success(v)if this instance represents success wherevis a string representation of the value or a stringFailure(x)if it is failure wherexis a string representation of the exception.-
-
Method Detail
-
getOrNull
final T getOrNull()
Returns the encapsulated value if this instance represents success or
nullif it is failure.This function is a shorthand for
getOrElse { null }(see getOrElse) orfold(onSuccess = { it }, onFailure = { null })(see fold).
-
exceptionOrNull
final Throwable exceptionOrNull()
Returns the encapsulated Throwable exception if this instance represents failure or
nullif it is success.This function is a shorthand for
fold(onSuccess = { null }, onFailure = { it })(see fold).
-
-
-
-