Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- enum Either<T> {
- case success(T)
- case error(Swift.Error)
- var successResult: T? {
- switch self {
- case .success(let result):
- return result
- case .error(_):
- return nil
- }
- }
- }
- protocol UseCaseProtocol {
- associatedtype ReturnType
- associatedtype Param
- func execute(_ params: Param, completion: @escaping ((Either<ReturnType>) -> Void))
- }
- struct UseCase<P, R> {
- typealias ReturnType = R
- typealias Param = P
- init<U>(_ useCase: U) where U: UseCaseProtocol, U.ReturnType == ReturnType, U.Param == Param {
- _execute = useCase.execute
- }
- func execute(_ params: P, completion: @escaping ((Either<R>) -> Void)) {
- _execute(params, completion)
- }
- let _execute: (P, @escaping (Either<R>) -> Void) -> Void
- }
Add Comment
Please, Sign In to add comment