Created
September 21, 2015 04:38
-
-
Save macbaszii/d59a45a0b8e190d4f05e to your computer and use it in GitHub Desktop.
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
| 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