Created
February 2, 2018 08:13
-
-
Save TomaszPietrowski/9be78864040c999b9f9730381fbea4f7 to your computer and use it in GitHub Desktop.
UseCase
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 characters
protocol UseCase { | |
associatedtype ResultType | |
func execute() -> ResultType | |
} | |
class UseCaseContainer<T>: UseCase { | |
private let useCase: UseCaseContainer<T> | |
init<U: UseCase>(_ useCase: U) where U.ResultType == T { | |
self.useCase = UseCaseContainer(useCase) | |
} | |
func execute() -> T { | |
return useCase.execute() | |
} | |
} | |
class CustomizableUseCase<T>: UseCase { | |
private let onExecute: () -> T | |
init(onExecute: @escaping () -> T) { | |
self.onExecute = onExecute | |
} | |
func execute() -> T { | |
return onExecute() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment