Created
January 11, 2021 19:31
-
-
Save petrosDemetrakopoulos/b942a39bfe7c2e6ad3dae5754f12d13d to your computer and use it in GitHub Desktop.
mutating functions
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
mutating func addExtras(id: Int, extras: [String:Int]) { | |
switch self { | |
case .preparePizza(id: let id, size: _, type: _, doughType: _): | |
self = .addedExtras(id: id, extras: extras) | |
case .addedExtras(id: let id, extras: _): | |
self = .addedExtras(id: id, extras: extras) | |
case .bakedPizza(id: let id): | |
print("Cannot add extras to Piza \(id) at this phase") | |
case .deliveredPizza(id: _): | |
print("Pizza \(id) must be baked before delivery") | |
} | |
} | |
mutating func bakePizza() { | |
switch self { | |
case .preparePizza(id: let id, size: _, type: _, doughType: _): | |
self = .bakedPizza(id: id) | |
case .addedExtras(id: let id, extras: _): | |
self = .bakedPizza(id: id) | |
case .bakedPizza(id: let id): | |
print("Pizza \(id) is already baked") | |
case .deliveredPizza(id: let id): | |
print("Pizza \(id) is already delivered") | |
} | |
} | |
mutating func deliverPizza() { | |
switch self { | |
case .preparePizza(id: let id, size: _, type: _, doughType: _): | |
print("Pizza \(id) must be baked before delivery") | |
case .addedExtras(id: let id, extras: _): | |
print("Cannot add extras to Pizza \(id) at this phase") | |
case .bakedPizza(id: let id): | |
self = .deliveredPizza(id: id) | |
case .deliveredPizza(id: let id): | |
print("Pizza \(id) is already delivered") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment