Last active
April 4, 2022 20:01
-
-
Save ericelliott/2b7f45b2ed3684440a3983bf3bf8cdab to your computer and use it in GitHub Desktop.
Pure functions have no timing dependency issues.
This file contains hidden or 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 x = { | |
val: 2 | |
}; | |
const x1 = x => Object.assign({}, x, { val: x.val + 1}); | |
const x2 = x => Object.assign({}, x, { val: x.val * 2}); | |
console.log(x1(x2(x)).val); // 5 | |
const y = { | |
val: 2 | |
}; | |
// Since there are no dependencies on outside variables, | |
// we don't need different functions to operate on different | |
// variables. | |
// this space intentionally left blank | |
// Because the functions don't mutate, you can call these | |
// functions as many times as you want, in any order, | |
// without changing the result of other function calls. | |
x2(y); | |
x1(y); | |
console.log(x1(x2(y)).val); // 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment