Last active
May 8, 2018 19:56
-
-
Save llinardos/f88574c15cf65760a13026591dea55bb to your computer and use it in GitHub Desktop.
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 ThingsService { | |
func getThings() -> Result<[Thing]> | |
func add(thing: Thing) -> Result<Bool> | |
} | |
class FakeThingsService: ThingsService { | |
private(set) var things: [Thing] | |
init(things: [Thing]) { | |
self.things = things | |
} | |
func getThings() -> Result<[Thing]> { | |
Thread.sleep(forTimeInterval: 1.0) | |
return .result(things) | |
} | |
func add(thing: Thing) -> Result<Bool> { | |
Thread.sleep(forTimeInterval: 1.0) | |
if things.contains(thing) { | |
return .success(false) | |
} else { | |
things.append(thing) | |
return .success(true) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment