Created
November 20, 2019 19:05
-
-
Save jeffypooo/7eebc98ba6568b374e55c6935ef2dca0 to your computer and use it in GitHub Desktop.
Revisions
-
jeffypooo created this gist
Nov 20, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ import io.reactivex.Observable import io.reactivex.Single /** * Something that can be executed. * @param ArgsType The argument data type. * @param ReturnType The return data type for the execution */ interface AbstractExecutable<ArgsType : Any, ReturnType : Any> { fun execute(data: ArgsType): ReturnType } /** * Convenience extension for [AbstractExecutable]s with [Unit] argument types. */ fun AbstractExecutable<Unit, *>.execute() = execute(data = Unit) /** * Base use-case types for the application. */ sealed class UseCase<A : Any, R : Any> : AbstractExecutable<A, R> { /** * Synchronous use-case. Executes and returns the result immediately. */ abstract class Synchronous<A : Any, R : Any> : UseCase<A, R>() /** * Reactive use-case. Returns an Observable stream of results. * @param R the element type for the [Observable]. */ abstract class RxObservable<A : Any, R : Any> : UseCase<A, Observable<R>>() /** * Reactive use-case. Returns a Single that emits the result type. * @param R the element type for the [Single]. */ abstract class RxSingle<A: Any, R: Any>: UseCase<A, Single<R>>() }