Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active April 26, 2018 21:21
Show Gist options
  • Select an option

  • Save dewey92/90bdd2a00e3d77b78239ca2b07b52911 to your computer and use it in GitHub Desktop.

Select an option

Save dewey92/90bdd2a00e3d77b78239ca2b07b52911 to your computer and use it in GitHub Desktop.
Menggunakan Reader
const accRepo: AccountRepo = {
find: no => ({ name: 'Bambang', email: 'tampan@tampan.com' })
};
declare function debit(no: string, amount: number): Reader<AccountRepo, Account>;
declare function credit(no: string, amount: number): Reader<AccountRepo, Account>;
declare function balance(no: string): Reader<AccountRepo, number>;
const transaksiBambangF = (no: string) => composeK(
() => balance(no),
() => credit(no, 80),
() => debit(no, 50),
() => debit(no, 100)
);
const finalbalanceF = transaksiBambangF('NL90DLBK0286293543')(accRepo);
// atau kalo mau pake ala OOP
const transaksiBambang = (no: string) => debit(no, 100)
.bind(() => debit(no, 50))
.bind(() => credit(no, 80))
.bind(() => balance(no))
const finalBalance = transaksiBambang('NL90DLBK0286293543').run(accRepo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment