Skip to content

Instantly share code, notes, and snippets.

@darrarski
Created July 19, 2018 21:53
Show Gist options
  • Save darrarski/357013aa4618abe06c09daf65de9488d to your computer and use it in GitHub Desktop.
Save darrarski/357013aa4618abe06c09daf65de9488d to your computer and use it in GitHub Desktop.
Swift factory helper
protocol Creating {
associatedtype Arguments
associatedtype Service
func create(_ arguments: Arguments) -> Service
}
extension Creating where Arguments == Void {
func create() -> Service {
return create(())
}
}
class AnyCreating<Arguments, Service>: Creating {
init<T: Creating>(_ creator: T) where T.Arguments == Arguments, T.Service == Service {
_create = creator.create
}
// MARK: Creating
func create(_ arguments: Arguments) -> Service {
return _create(arguments)
}
// MARK: Private
private let _create: (Arguments) -> Service
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment