Skip to content

Instantly share code, notes, and snippets.

@chaliy
Created January 2, 2010 17:39
Show Gist options
  • Save chaliy/267574 to your computer and use it in GitHub Desktop.
Save chaliy/267574 to your computer and use it in GitHub Desktop.
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