Skip to content

Instantly share code, notes, and snippets.

@petrosDemetrakopoulos
Created January 11, 2021 19:31
Show Gist options
  • Save petrosDemetrakopoulos/b942a39bfe7c2e6ad3dae5754f12d13d to your computer and use it in GitHub Desktop.
Save petrosDemetrakopoulos/b942a39bfe7c2e6ad3dae5754f12d13d to your computer and use it in GitHub Desktop.
mutating functions
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