diff options
Diffstat (limited to 'pbt/ts/src/bank.ts')
| -rw-r--r-- | pbt/ts/src/bank.ts | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/pbt/ts/src/bank.ts b/pbt/ts/src/bank.ts index e5619f4..e388354 100644 --- a/pbt/ts/src/bank.ts +++ b/pbt/ts/src/bank.ts @@ -1,4 +1,4 @@ -import {Option, fromNullable} from 'fp-ts/lib/Option'; +import {Option, fromNullable, isSome, matchW} from 'fp-ts/lib/Option'; // keep it simple export type Account = string; @@ -32,11 +32,27 @@ export class SimpleBank implements Bank { } deposit(account: Account, amt: number): void { - throw new Error('Method not implemented.'); + const current = this.balance(account); + matchW( + () => { + throw new Error(`Unknown account ${account}`); + }, + (bal: number) => { + this.accounts.set(account, bal + amt); + }, + )(current); } withdraw(account: Account, amt: number): void { - throw new Error('Method not implemented.'); + const current = this.balance(account); + matchW( + () => { + throw new Error(`Unknown account ${account}`); + }, + (bal: number) => { + this.accounts.set(account, bal - amt); + }, + )(current); } } |
