Created
March 31, 2019 18:00
-
-
Save polac24/e1b04b6f6cbb51d7ffe6c4ebaf8c7912 to your computer and use it in GitHub Desktop.
This file contains 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 DefaultProvidable { | |
static var defaultValue: Self {get} | |
} | |
extension Bool: DefaultProvidable { | |
static let defaultValue = false | |
} | |
extension Optional: DefaultProvidable { | |
static var defaultValue: Optional<Wrapped> {return nil} | |
} | |
... | |
func niceStub<I,O: DefaultProvidable>(of: (I) -> (O)) -> (I) -> (O){ | |
return { _ in O.defaultValue } | |
} | |
class DatabaseStub: Database { | |
lazy var addUserAction = niceStub(of: addUser) // returns false | |
func addUser(name: String) -> Bool { | |
return addUserAction(name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment