diff options
Diffstat (limited to 'pbt/ts/src/bank.ts')
| -rw-r--r-- | pbt/ts/src/bank.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pbt/ts/src/bank.ts b/pbt/ts/src/bank.ts new file mode 100644 index 0000000..bee9dfc --- /dev/null +++ b/pbt/ts/src/bank.ts @@ -0,0 +1,31 @@ +import {Option, fromNullable} from 'fp-ts/lib/Option'; + +// keep it simple +export type Account = string; + +export interface Bank { + balance: (account: Account) => Option<number>; + deposit: (account: Account, amt: number) => void; + withdraw: (account: Account, amt: number) => void; +} + +export class SimpleBank implements Bank { + private accounts: Map<Account, number>; + + constructor(accounts: Map<Account, number>) { + // clone the content of the map + this.accounts = new Map(accounts); + } + + balance(account: Account): Option<number> { + return fromNullable(this.accounts.get(account)); + } + + deposit(account: Account, amt: number): void { + throw new Error('Method not implemented.'); + } + + withdraw(account: Account, amt: number): void { + throw new Error('Method not implemented.'); + } +} |
