Skip to content

Instantly share code, notes, and snippets.

@TomaszPietrowski
Created February 2, 2018 08:13
Show Gist options
  • Save TomaszPietrowski/9be78864040c999b9f9730381fbea4f7 to your computer and use it in GitHub Desktop.
Save TomaszPietrowski/9be78864040c999b9f9730381fbea4f7 to your computer and use it in GitHub Desktop.
UseCase
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