Created
February 28, 2020 17:06
-
-
Save jbmilgrom/fbf9bb74f7da6a313ff11ae7c29189b1 to your computer and use it in GitHub Desktop.
Body of a functional program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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