Skip to content

Instantly share code, notes, and snippets.

@kingcons
Created November 12, 2014 03:22
Show Gist options
  • Save kingcons/68baa364b98ed621bbba to your computer and use it in GitHub Desktop.
Save kingcons/68baa364b98ed621bbba to your computer and use it in GitHub Desktop.
JS Cons Trick
(function () {
var exports = {};
exports.makeArray = function (a, b) {
return function(chooser) {
return chooser(a, b);
};
};
exports.first = function (array) {
return array(function (a, b) { return a; });
}
exports.rest = function (array) {
return array(function (a, b) { return b; });
}
// TODO:
// 1. Add Retrieval by Index.
// 2. Add nice print representation.
// 3. Add parser for print representation.
window.toy = exports;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment