Created
November 12, 2014 03:22
-
-
Save kingcons/68baa364b98ed621bbba to your computer and use it in GitHub Desktop.
JS Cons Trick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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