summaryrefslogtreecommitdiff
path: root/pbt/ts/src/bank.ts
blob: bee9dfc62db92e5b9fd4ab4779f75c4b874c7421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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.');
  }
}