Skip to content

Instantly share code, notes, and snippets.

@superdav42
Forked from AutoSponge/lambda_list.js
Created April 5, 2013 16:55
Show Gist options
  • Select an option

  • Save superdav42/5320849 to your computer and use it in GitHub Desktop.

Select an option

Save superdav42/5320849 to your computer and use it in GitHub Desktop.
function empty_list(selector) {
return selector(undefined, undefined, true);
};
function prepend(el, list) {
return function(selector) {
return selector(el, list, false);
};
};
//selector
function select(n) {
return function from(list) {
return list(function () {
return arguments[n];
});
};
}
var head = select(0);
var tail = select(1);
var is_empty = select(2);
var names = prepend("Alice",
prepend("Bob",
prepend("Candice",
empty_list)));
console.log(is_empty(names));
// False
console.log(head(names));
// Alice
console.log(tail(names));
// Some function representing the list of ("Bob", "Candice")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment