Skip to content

Instantly share code, notes, and snippets.

@mythril
Last active June 21, 2018 20:46
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 mythril/8a01b5b44c182c452205c1d5e37d4cb6 to your computer and use it in GitHub Desktop.
Save mythril/8a01b5b44c182c452205c1d5e37d4cb6 to your computer and use it in GitHub Desktop.
pure_functional_javascript_queue.js
function pair(a, b) {
return function (selector) {
if (selector) {
return a;
}
return b;
}
}
function first(p) {
if (p) {
return p(true);
}
}
function remaining(p) {
if (p) {
return p(false);
}
}
function enqueue(element, p) {
return pair(element, p);
}
function get(nth, q) {
if (nth === 0) {
return first(q);
}
return get(nth - 1, remaining(q));
}
console.log(get(2, enqueue(3, enqueue(2, enqueue(1)))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment