Created
July 19, 2018 21:53
-
-
Save darrarski/357013aa4618abe06c09daf65de9488d to your computer and use it in GitHub Desktop.
Swift factory helper
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 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