mirror of
https://github.com/AU-COVIDSafe/mobile-ios.git
synced 2025-04-19 21:15:21 +00:00
COVIDSafe code from version 1.1
This commit is contained in:
commit
3640e52eb2
330 changed files with 261540 additions and 0 deletions
35
CovidSafe/Feedback/Sources/Outcome.swift
Normal file
35
CovidSafe/Feedback/Sources/Outcome.swift
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright © 2020 Australian Government All rights reserved.
|
||||
|
||||
import Foundation
|
||||
|
||||
public typealias VoidOutcome = Outcome<Void>
|
||||
|
||||
public enum Outcome<T> {
|
||||
case success(T)
|
||||
case error(Error)
|
||||
case cancelled
|
||||
|
||||
public init(resultOrNil: T?, errorOrNil: Error?) {
|
||||
if let error = errorOrNil {
|
||||
self = .error(error)
|
||||
return
|
||||
}
|
||||
if let result = resultOrNil {
|
||||
self = .success(result)
|
||||
return
|
||||
}
|
||||
self = .error(ProgrammerError.encounteredNilResultAndNilErrorOutcome)
|
||||
}
|
||||
|
||||
public init<A>(somethingOrNothing: A?, resultIfSomething: T, errorIfNothing: Error) {
|
||||
if somethingOrNothing != nil {
|
||||
self = .success(resultIfSomething)
|
||||
} else {
|
||||
self = .error(errorIfNothing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum ProgrammerError: Error {
|
||||
case encounteredNilResultAndNilErrorOutcome
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue