public class ResultKt
| Modifier and Type | Method and Description |
|---|---|
static <VALUE,NEW_VALUE> |
fold(Result<? extends VALUE> $receiver,
kotlin.jvm.functions.Function1<? super VALUE,? extends NEW_VALUE> onSuccess,
kotlin.jvm.functions.Function1<? super java.lang.Throwable,? extends NEW_VALUE> onError)
Returns the the result of
onSuccess for encapsulated value if this instance represents class Success
or the result of onError function for encapsulated exception if it is class Error. |
static <VALUE> VALUE |
getOrCancel(Result<? extends VALUE> $receiver,
kotlin.jvm.functions.Function1<? super java.lang.Throwable,kotlin.Unit> doBeforeThrow)
Returns the encapsulated value if this instance represents
class Success or
throws CancellationException with Error.error as its cause if it is class Error. |
static <VALUE> VALUE |
getOrDefault(Result<? extends VALUE> $receiver,
VALUE defaultValue)
Returns the encapsulated value if this instance represents
class Success or defaultValue
for encapsulated exception if it is class Error. |
static <VALUE> VALUE |
getOrElse(Result<? extends VALUE> $receiver,
kotlin.jvm.functions.Function1<? super java.lang.Throwable,? extends VALUE> onError)
Returns the encapsulated value if this instance represents
class Success or result of onError
for encapsulated exception if it is class Error. |
static <VALUE> VALUE |
getOrNull(Result<? extends VALUE> $receiver)
Returns the encapsulated value if this instance represents
class Success or null
for encapsulated exception if it is class Error. |
static <VALUE> VALUE |
getOrThrow(Result<? extends VALUE> $receiver,
kotlin.jvm.functions.Function1<? super java.lang.Throwable,kotlin.Unit> doBeforeThrow)
Returns the encapsulated value if this instance represents
class Success or
throws the encapsulated exception if it is class Error. |
static <VALUE,NEW_VALUE> |
map(Result<? extends VALUE> $receiver,
kotlin.jvm.functions.Function1<? super VALUE,? extends NEW_VALUE> transform)
Returns the encapsulated result of the given
transform function applied to encapsulated value
if this instance represents class Success or the original encapsulated exception if it is class Error. |
static <VALUE,NEW_VALUE> |
mapCatching(Result<? extends VALUE> $receiver,
kotlin.jvm.functions.Function1<? super VALUE,? extends NEW_VALUE> transform)
Returns the encapsulated result of the given
transform function applied to encapsulated value
if this instance represents class Success or the original encapsulated exception if it is class Error. |
static <VALUE> Result<VALUE> |
recover(Result<? extends VALUE> $receiver,
kotlin.jvm.functions.Function1<? super java.lang.Throwable,? extends VALUE> transform)
Returns the encapsulated result of the given
transform function applied to encapsulated exception
if this instance represents class Error or the original encapsulated value if it is class Success. |
static <VALUE> Result<VALUE> |
recoverCatching(Result<? extends VALUE> $receiver,
kotlin.jvm.functions.Function1<? super java.lang.Throwable,? extends VALUE> transform)
Returns the encapsulated result of the given
transform function applied to encapsulated exception
if this instance represents class Error or the original encapsulated value if it is class Success. |
static <VALUE> Result<VALUE> |
tryCatch(kotlin.jvm.functions.Function0<? extends VALUE> block)
Calls the specified function
block and returns class Success with encapsulated result if invocation was successful,
catching and returning class Error with any thrown exception except CancellationException. |
@NotNull public static <VALUE> Result<VALUE> tryCatch(@NotNull kotlin.jvm.functions.Function0<? extends VALUE> block)
Calls the specified function block and returns class Success with encapsulated result if invocation was successful,
catching and returning class Error with any thrown exception except CancellationException.
block,
class Success,
class Error@Nullable
public static <VALUE> VALUE getOrNull(@NotNull
Result<? extends VALUE> $receiver)
Returns the encapsulated value if this instance represents class Success or null
for encapsulated exception if it is class Error.
If Error.error is CancellationException then this error is rethrown.
class Success,
class Errorpublic static <VALUE> VALUE getOrDefault(@NotNull
Result<? extends VALUE> $receiver,
VALUE defaultValue)
Returns the encapsulated value if this instance represents class Success or defaultValue
for encapsulated exception if it is class Error.
If Error.error is CancellationException then this error is rethrown.
class Success,
defaultValue,
class Errorpublic static <VALUE> VALUE getOrElse(@NotNull
Result<? extends VALUE> $receiver,
@NotNull
kotlin.jvm.functions.Function1<? super java.lang.Throwable,? extends VALUE> onError)
Returns the encapsulated value if this instance represents class Success or result of onError
for encapsulated exception if it is class Error.
If Error.error is CancellationException then this error is rethrown.
class Success,
onError,
class Errorpublic static <VALUE> VALUE getOrThrow(@NotNull
Result<? extends VALUE> $receiver,
@NotNull
kotlin.jvm.functions.Function1<? super java.lang.Throwable,kotlin.Unit> doBeforeThrow)
Returns the encapsulated value if this instance represents class Success or
throws the encapsulated exception if it is class Error.
If Error.error is not CancellationException then doBeforeThrow is called before throw.
class Success,
class Error,
doBeforeThrowpublic static <VALUE> VALUE getOrCancel(@NotNull
Result<? extends VALUE> $receiver,
@NotNull
kotlin.jvm.functions.Function1<? super java.lang.Throwable,kotlin.Unit> doBeforeThrow)
Returns the encapsulated value if this instance represents class Success or
throws CancellationException with Error.error as its cause if it is class Error.
This method should be used in the case when you want to safely cancel your coroutine from inside.
If Error.error is not CancellationException then doBeforeThrow is called before throw.
class Success,
class Error,
doBeforeThrow@NotNull public static <VALUE,NEW_VALUE> Result<NEW_VALUE> map(@NotNull Result<? extends VALUE> $receiver, @NotNull kotlin.jvm.functions.Function1<? super VALUE,? extends NEW_VALUE> transform)
Returns the encapsulated result of the given transform function applied to encapsulated value
if this instance represents class Success or the original encapsulated exception if it is class Error.
Note, that an exception thrown by transform function is rethrown by this function.
See mapCatching for an alternative that encapsulates exceptions.
transform,
class Success,
class Error,
transform,
mapCatching@NotNull public static <VALUE,NEW_VALUE> Result<NEW_VALUE> mapCatching(@NotNull Result<? extends VALUE> $receiver, @NotNull kotlin.jvm.functions.Function1<? super VALUE,? extends NEW_VALUE> transform)
Returns the encapsulated result of the given transform function applied to encapsulated value
if this instance represents class Success or the original encapsulated exception if it is class Error.
Any exception thrown by transform function is caught, encapsulated as a failure and returned by this function.
See map for an alternative that rethrows exceptions.
transform,
class Success,
class Error,
transform,
map@NotNull public static <VALUE> Result<VALUE> recover(@NotNull Result<? extends VALUE> $receiver, @NotNull kotlin.jvm.functions.Function1<? super java.lang.Throwable,? extends VALUE> transform)
Returns the encapsulated result of the given transform function applied to encapsulated exception
if this instance represents class Error or the original encapsulated value if it is class Success.
If Error.error is CancellationException then this error is rethrown.
Note, that an exception thrown by transform function is rethrown by this function.
See recoverCatching for an alternative that encapsulates exceptions.
transform,
class Error,
class Success,
transform,
recoverCatching@NotNull public static <VALUE> Result<VALUE> recoverCatching(@NotNull Result<? extends VALUE> $receiver, @NotNull kotlin.jvm.functions.Function1<? super java.lang.Throwable,? extends VALUE> transform)
Returns the encapsulated result of the given transform function applied to encapsulated exception
if this instance represents class Error or the original encapsulated value if it is class Success.
If Error.error is CancellationException then this error is rethrown.
Any other exception thrown by transform function is caught, encapsulated as a failure and returned by this function.
See recover for an alternative that rethrows exceptions.
transform,
class Error,
class Success,
transform,
recoverpublic static <VALUE,NEW_VALUE> NEW_VALUE fold(@NotNull
Result<? extends VALUE> $receiver,
@NotNull
kotlin.jvm.functions.Function1<? super VALUE,? extends NEW_VALUE> onSuccess,
@NotNull
kotlin.jvm.functions.Function1<? super java.lang.Throwable,? extends NEW_VALUE> onError)
Returns the the result of onSuccess for encapsulated value if this instance represents class Success
or the result of onError function for encapsulated exception if it is class Error.
If Error.error is CancellationException then this error is rethrown.
onSuccess,
class Success,
onError,
class Error