Skip to content

Instantly share code, notes, and snippets.

@whitelizard
Last active December 20, 2019 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whitelizard/d0c00bf4b0418481e795da837ab492ff to your computer and use it in GitHub Desktop.
Save whitelizard/d0c00bf4b0418481e795da837ab492ff to your computer and use it in GitHub Desktop.
Functional style programming tests
let c1 = circle([2.5, 0], 1.5);
let c2 = circle([-2, 0], 2);
const c2ref = c2; // Use a reference to c2 at this point in time
area(c1.r); // -> 7.0685834705770345
area(c2.r); // -> 12.566370614359172
let hit;
[hit, c1, c2] = intersect(c1, c2);
hit; // -> false
c1.hits; // -> 0
c1 = setPos(c1, [1, 0]);
[hit, c1, c2] = intersect(c1, c2);
hit; // -> true
c1.hits; // -> 1
c2.hits; // -> 1
c2ref.hits; // -> 0. The ref is pointing to the initial c2
c1.hits = 4;
c1.hits; // -> 4. This is not great. Mutation is possible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment