Created
January 2, 2010 17:39
-
-
Save chaliy/267574 to your computer and use it in GitHub Desktop.
This file contains 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
module Bank | |
// Model | |
type Amount = decimal | |
type Balance = { | |
CurrentAmount: Amount | |
} | |
type ActiveAccount = { | |
AccountNumber: string; | |
Balance: Balance | |
} | |
type Events = | |
| LargeAmountOfCashWithdrawnEvent of ActiveAccount * Amount | |
| CashWithdrawnEvent of ActiveAccount * Amount | |
// Behavour | |
let WithdrawalCash(account, amount) = transaction { | |
ensure ( account.IsStillOpen | |
&& account.Balance.CurrentAmount - amount < 0.0m | |
) | |
let newBalance = account.Balance.CurrentAmount - amount | |
if (newBalance > 100.0m) then | |
yield LargeAmountOfCashWithdrawnEvent(account, newBalance) | |
yield CashWithdrawnEvent(account, newBalance) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment