Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Last active April 4, 2022 20:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericelliott/2b7f45b2ed3684440a3983bf3bf8cdab to your computer and use it in GitHub Desktop.
Save ericelliott/2b7f45b2ed3684440a3983bf3bf8cdab to your computer and use it in GitHub Desktop.
Pure functions have no timing dependency issues.
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