Skip to content

Instantly share code, notes, and snippets.

@jbmilgrom
Created February 28, 2020 17:06
Show Gist options
  • Save jbmilgrom/fbf9bb74f7da6a313ff11ae7c29189b1 to your computer and use it in GitHub Desktop.
Save jbmilgrom/fbf9bb74f7da6a313ff11ae7c29189b1 to your computer and use it in GitHub Desktop.
Body of a functional program
const withdraw = (balance, amount) => balance - amount;
const ATM = (state = {balance: 100, amount: 10}, event) => {
switch (event.type) {
case 'WITHDRAW':
return {
...state,
balance: withdraw(state.balance, state.amount),
};
case 'WITHDRAWAL_AMOUNT':
return {
...state,
amount: parseInt(event.amount),
};
default:
return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment