Skip to content

Instantly share code, notes, and snippets.

@llinardos
Last active May 8, 2018 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llinardos/f88574c15cf65760a13026591dea55bb to your computer and use it in GitHub Desktop.
Save llinardos/f88574c15cf65760a13026591dea55bb to your computer and use it in GitHub Desktop.
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