Skip to content

Instantly share code, notes, and snippets.

@macbaszii
Created September 21, 2015 04:38
Show Gist options
  • Select an option

  • Save macbaszii/d59a45a0b8e190d4f05e to your computer and use it in GitHub Desktop.

Select an option

Save macbaszii/d59a45a0b8e190d4f05e to your computer and use it in GitHub Desktop.
func canPurchaseItem(item: Item, forUser user: User) throws {
let filtered = allItems.filter { (item: Item) -> Bool in
return item === item;
}
if filtered.count == 0 {
throw PurchaseError.OutOfStockItem
}
if user.money - item.price < 0 {
throw PurchaseError.InsufficientFunds
}
purchaseItem(item, forUser: user)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment