Package app.futured.arkitekt.crusecases

Types

Link copied to clipboard
abstract class BaseCrViewModel<S : ViewState> : BaseViewModel<S> , CoroutineScopeOwner

Base ViewModel class prepared for providing data to UI through LiveData and obtaining data from Stores (Repositories) by executing Coroutine based use cases like UseCase and FlowUseCase.

Link copied to clipboard
interface CoroutineScopeOwner

This interface gives your class ability to execute UseCase and FlowUseCase Coroutine use cases. You may find handy to implement this interface in custom Presenters, ViewHolders etc. It is your responsibility to cancel coroutineScope when when all running tasks should be stopped.

Link copied to clipboard
class Error(error: Throwable) : Result<Nothing>

Represents a failed Result, containing an error.

Link copied to clipboard
abstract class FlowUseCase<ARGS, T>

Base Flow use case meant to use in CoroutineScopeOwner implementations

Link copied to clipboard
sealed class Result<out VALUE>

A discriminated union that encapsulates successful outcome either with Success or with Error

Link copied to clipboard
class Success<VALUE>(value: VALUE) : Result<VALUE>

Represents a successful Result, containing a value.

Link copied to clipboard
abstract class UseCase<ARGS, T>

Base Coroutine use case meant to use in CoroutineScopeOwner implementations

Functions

Link copied to clipboard
inline fun <VALUE, NEW_VALUE> Result<VALUE>.fold(onSuccess: (VALUE) -> NEW_VALUE, onError: (Throwable) -> NEW_VALUE): NEW_VALUE

Returns the the result of onSuccess for encapsulated value if this instance represents Success or the result of onError function for encapsulated exception if it is Error.

Link copied to clipboard
inline fun <VALUE> Result<VALUE>.getOrCancel(doBeforeThrow: (Throwable) -> Unit = {}): VALUE

Returns the encapsulated value if this instance represents Success or throws CancellationException with Error.error as its cause if it is Error.

Link copied to clipboard
fun <VALUE> Result<VALUE>.getOrDefault(defaultValue: VALUE): VALUE

Returns the encapsulated value if this instance represents Success or defaultValue for encapsulated exception if it is Error.

Link copied to clipboard
inline fun <VALUE> Result<VALUE>.getOrElse(onError: (Throwable) -> VALUE): VALUE

Returns the encapsulated value if this instance represents Success or result of onError for encapsulated exception if it is Error.

Link copied to clipboard
fun <VALUE> Result<VALUE>.getOrNull(): VALUE?

Returns the encapsulated value if this instance represents Success or null for encapsulated exception if it is Error.

Link copied to clipboard
inline fun <VALUE> Result<VALUE>.getOrThrow(doBeforeThrow: (Throwable) -> Unit = {}): VALUE

Returns the encapsulated value if this instance represents Success or throws the encapsulated exception if it is Error.

Link copied to clipboard
inline fun <VALUE, NEW_VALUE> Result<VALUE>.map(transform: (VALUE) -> NEW_VALUE): Result<NEW_VALUE>

Returns the encapsulated result of the given transform function applied to encapsulated value if this instance represents Success or the original encapsulated exception if it is Error.

Link copied to clipboard
inline fun <VALUE, NEW_VALUE> Result<VALUE>.mapCatching(transform: (VALUE) -> NEW_VALUE): Result<NEW_VALUE>

Returns the encapsulated result of the given transform function applied to encapsulated value if this instance represents Success or the original encapsulated exception if it is Error.

Link copied to clipboard
inline fun <VALUE> Result<VALUE>.recover(transform: (Throwable) -> VALUE): Result<VALUE>

Returns the encapsulated result of the given transform function applied to encapsulated exception if this instance represents Error or the original encapsulated value if it is Success.

Link copied to clipboard
inline fun <VALUE> Result<VALUE>.recoverCatching(transform: (Throwable) -> VALUE): Result<VALUE>

Returns the encapsulated result of the given transform function applied to encapsulated exception if this instance represents Error or the original encapsulated value if it is Success.

Link copied to clipboard
inline fun <VALUE> tryCatch(block: () -> VALUE): Result<VALUE>

Calls the specified function block and returns Success with encapsulated result if invocation was successful, catching and returning Error with any thrown exception except CancellationException.