Class NetworkResultKt
-
- All Implemented Interfaces:
public final class NetworkResultKt
-
-
Method Summary
Modifier and Type Method Description final static <R extends Any> NetworkResult<R>runCatching(Function0<R> block)Calls the specified function block and returns its encapsulated result if invocation was successful, catching any Throwable exception that was thrown from the block function execution and encapsulating it as a failure. final static <T extends Any, R extends Any> NetworkResult<R>runCatching(T $self, Function1<T, R> block)Calls the specified function block with thisvalue as its receiver and returns its encapsulated result if invocation was successful, catching any Throwable exception that was thrown from the block function execution and encapsulating it as a failure.final static <T extends Any> TgetOrThrow(NetworkResult<T> $self)Returns the encapsulated value if this instance represents success or throws the encapsulated Throwable exception if it is failure. final static <R extends Any, T extends R> RgetOrElse(NetworkResult<T> $self, Function1<Throwable, R> onFailure)Returns the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failure. final static <R extends Any, T extends R> RgetOrDefault(NetworkResult<T> $self, R defaultValue)Returns the encapsulated value if this instance represents success or the defaultValue if it is failure. final static <R extends Any, T extends Any> Rfold(NetworkResult<T> $self, Function1<T, R> onSuccess, Function1<Throwable, R> onFailure)Returns the result of onSuccess for the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failure. final static <R extends Any, T extends Any> NetworkResult<R>map(NetworkResult<T> $self, Function1<T, R> transform)Returns the encapsulated result of the given transform function applied to the encapsulated value if this instance represents success or the original encapsulated Throwable exception if it is failure. final static <R extends Any, T extends Any> NetworkResult<R>mapCatching(NetworkResult<T> $self, Function1<T, R> transform)Returns the encapsulated result of the given transform function applied to the encapsulated value if this instance represents success or the original encapsulated Throwable exception if it is failure. final static <R extends Any, T extends R> NetworkResult<R>recover(NetworkResult<T> $self, Function1<Throwable, R> transform)Returns the encapsulated result of the given transform function applied to the encapsulated Throwable exception if this instance represents failure or the original encapsulated value if it is success. final static <R extends Any, T extends R> NetworkResult<R>recoverCatching(NetworkResult<T> $self, Function1<Throwable, R> transform)Returns the encapsulated result of the given transform function applied to the encapsulated Throwable exception if this instance represents failure or the original encapsulated value if it is success. final static <T extends Any> NetworkResult<T>onFailure(NetworkResult<T> $self, Function1<Throwable, Unit> action)Performs the given action on the encapsulated Throwable exception if this instance represents failure. final static <T extends Any> NetworkResult<T>onSuccess(NetworkResult<T> $self, Function1<T, Unit> action)Performs the given action on the encapsulated value if this instance represents success. -
-
Method Detail
-
runCatching
final static <R extends Any> NetworkResult<R> runCatching(Function0<R> block)
Calls the specified function block and returns its encapsulated result if invocation was successful, catching any Throwable exception that was thrown from the block function execution and encapsulating it as a failure.
-
runCatching
final static <T extends Any, R extends Any> NetworkResult<R> runCatching(T $self, Function1<T, R> block)
Calls the specified function block with
thisvalue as its receiver and returns its encapsulated result if invocation was successful, catching any Throwable exception that was thrown from the block function execution and encapsulating it as a failure.
-
getOrThrow
final static <T extends Any> T getOrThrow(NetworkResult<T> $self)
Returns the encapsulated value if this instance represents success or throws the encapsulated Throwable exception if it is failure.
This function is a shorthand for
getOrElse { throw it }(see getOrElse).
-
getOrElse
final static <R extends Any, T extends R> R getOrElse(NetworkResult<T> $self, Function1<Throwable, R> onFailure)
Returns the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failure.
Note, that this function rethrows any Throwable exception thrown by onFailure function.
This function is a shorthand for
fold(onSuccess = { it }, onFailure = onFailure)(see fold).
-
getOrDefault
final static <R extends Any, T extends R> R getOrDefault(NetworkResult<T> $self, R defaultValue)
Returns the encapsulated value if this instance represents success or the defaultValue if it is failure.
This function is a shorthand for
getOrElse { defaultValue }(see getOrElse).
-
fold
final static <R extends Any, T extends Any> R fold(NetworkResult<T> $self, Function1<T, R> onSuccess, Function1<Throwable, R> onFailure)
Returns the result of onSuccess for the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failure.
Note, that this function rethrows any Throwable exception thrown by onSuccess or by onFailure function.
-
map
final static <R extends Any, T extends Any> NetworkResult<R> map(NetworkResult<T> $self, Function1<T, R> transform)
Returns the encapsulated result of the given transform function applied to the encapsulated value if this instance represents success or the original encapsulated Throwable exception if it is failure.
Note, that this function rethrows any Throwable exception thrown by transform function. See mapCatching for an alternative that encapsulates exceptions.
-
mapCatching
final static <R extends Any, T extends Any> NetworkResult<R> mapCatching(NetworkResult<T> $self, Function1<T, R> transform)
Returns the encapsulated result of the given transform function applied to the encapsulated value if this instance represents success or the original encapsulated Throwable exception if it is failure.
This function catches any Throwable exception thrown by transform function and encapsulates it as a failure. See map for an alternative that rethrows exceptions from
transformfunction.
-
recover
final static <R extends Any, T extends R> NetworkResult<R> recover(NetworkResult<T> $self, Function1<Throwable, R> transform)
Returns the encapsulated result of the given transform function applied to the encapsulated Throwable exception if this instance represents failure or the original encapsulated value if it is success.
Note, that this function rethrows any Throwable exception thrown by transform function. See recoverCatching for an alternative that encapsulates exceptions.
-
recoverCatching
final static <R extends Any, T extends R> NetworkResult<R> recoverCatching(NetworkResult<T> $self, Function1<Throwable, R> transform)
Returns the encapsulated result of the given transform function applied to the encapsulated Throwable exception if this instance represents failure or the original encapsulated value if it is success.
This function catches any Throwable exception thrown by transform function and encapsulates it as a failure. See recover for an alternative that rethrows exceptions.
-
onFailure
final static <T extends Any> NetworkResult<T> onFailure(NetworkResult<T> $self, Function1<Throwable, Unit> action)
Performs the given action on the encapsulated Throwable exception if this instance represents failure. Returns the original
Resultunchanged.
-
onSuccess
final static <T extends Any> NetworkResult<T> onSuccess(NetworkResult<T> $self, Function1<T, Unit> action)
Performs the given action on the encapsulated value if this instance represents success. Returns the original
Resultunchanged.
-
-
-
-