Skip to content

Instantly share code, notes, and snippets.

var vendingMachine = VendingMachine()
vendingMachine.coinsDeposited = 8
do {
try buyFavoriteSnack(person: "Alice", vendingMachine: vendingMachine)
print("Success! Yum.")
} catch VendingMachineError.invalidSelection {
print("Invalid Selection.")
} catch VendingMachineError.outOfStock {
print("Out of Stock.")
} catch VendingMachineError.insufficientFunds(let coinsNeeded) {
protocol Validatable { }
extension Int: Validatable { }
extension String: Validatable { }
protocol ValidatorConvertible {
associatedtype ValidationType
func validated(_ value: ValidationType) -> Promise<ValidationType>
}