Run the following code against [Ramda][ramda].
// Simple predicate to test whether a number is even
var even = function(n) {return (n % 2) === 0;};
// Generates an infinite list of Fibonacci numbers
var fibsgen = generator(
| (function() { | |
| var split = {}, intervalData, | |
| timeComponent = { | |
| seconds: function (split) {return split.seconds * 6;}, | |
| minutes: function (split) {return (split.minutes + (split.seconds / 60)) * 6;}, | |
| hours: function (split) {return (split.hours % 12 * 30 ) + split.minutes / 2;} | |
| }; | |
| var SVG = (function() { | |
| var SVG = function(config) { |
| var app = (function() { | |
| var app = (function () { | |
| var cache = {}; | |
| var getTopic = function (topic) { | |
| return cache[topic] || (cache[topic] = []); | |
| }; | |
| var emitData = function(data, callback) { | |
| callback.call(null, data); |
| (function(global) { | |
| // TODO: Make a tree structure from type objects' optional `parentKey` properties. Do a depth-first search of | |
| // this tree instead of the simple linear search of `Object.keys`. | |
| var types = {}; | |
| global.Functor = function(config) { | |
| types[config.key] = config; | |
| }; | |
| global.fmap = curry(function(f, obj) { |
| (function(global) { | |
| var types = function(obj) { | |
| throw new TypeError("fmap called on unregistered type: " + obj); | |
| }; | |
| // inefficient as hell, but as long as there aren't too many types.... | |
| global.Functor = function(type, defs) { | |
| var oldTypes = types; | |
| types = function(obj) { | |
| if (type.prototype.isPrototypeOf(obj)) { |
| var compose = function compose(f) { | |
| var queue = f ? [f] : []; | |
| var fn = function fn(g) { | |
| if (arguments.length) { | |
| queue.push(g); | |
| return fn; | |
| } | |
| return function() { | |
| var args = Array.prototype.slice.call(arguments); | |
| queue.forEach(function(func) { |
| Function.prototype.compose = function(g) { | |
| var fn = this; | |
| return function() { | |
| return fn.call(this, g.apply(this, arguments)); | |
| }; | |
| }; | |
| Function.prototype.pipe = function(g) { | |
| var fn = this; | |
| return function() { |
| var fibonacci = (function() { | |
| var fib = function(curr, next, n) { | |
| return (n === 0) ? curr : fib(next, curr + next, n - 1); | |
| }; | |
| return function(n) { | |
| return fib(0, 1, n); | |
| } | |
| }()); |
inspired to understand this from:
compare with https://github.com/Gozala/js-tail-call/blob/master/core.js for speed (after refactoring to work like his does)
| // clean and pure: | |
| function cons(x, y) { | |
| return function(pick) { | |
| return pick(x, y); | |
| } | |
| } | |
| // does more stuff: | |
| function cons(x, y) { | |
| var fn = function(pick) { |