This file contains 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
// 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) { |
This file contains 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 recur(fn) { | |
return function () { | |
var bounce = fn.apply(this, arguments); | |
while (bounce.onTheTrampoline) { | |
bounce = bounce(); | |
} | |
return bounce; | |
}; | |
} | |
var sum1 = recur(function sum(x, y) { |
This file contains 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
// Paul's clean-up | |
function deDupe(dupeCheck, list) { | |
return list.reduce(function (prev, curr) { | |
if (!dupeCheck(curr, prev)) { | |
prev.push(curr); | |
} | |
return prev; | |
}, []); | |
} |
This file contains 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
/* | |
Factorial of course. Can't talk about recursion without factorial. | |
*/ | |
function basicFactorial(n) { | |
return n === 0 ? 1 : n * basicFactorial(n-1); | |
} | |
/* | |
Define a *non-recursive* function that has the factorial function as a fixpoint. | |
*/ |
This file contains 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
/* | |
Fibonacci infinite stream generator. Not hugely exciting yet | |
*/ | |
var fgen = (function() { | |
var fn1 = 0, fn2 = 1; | |
f = function f() { | |
var curr = fn2; | |
fn2 = fn1; | |
fn1 = fn1 + curr; | |
return fn1; |
This file contains 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 fail(x) { return []; } | |
function succeed(x) { return [x]; } | |
function disj(f1, f2) { | |
return function(x) { | |
return f1(x).concat(f2(x)); | |
} | |
} | |
function conj(f1, f2) { |
This file contains 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(global) { | |
global.Functor = function(conf) { | |
Functor.types[conf.key] = { | |
obj: conf.obj, | |
fmap: conf.fmap | |
}; | |
}; | |
Functor.types = {}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
// require("ramda"); | |
var gens = (function() { | |
var trampoline = function(fn) { | |
var result = fn.apply(this, tail(arguments)); | |
while (typeof result == "function") { | |
result = result(); | |
} | |
return result; | |
}; |
This file contains 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
// currently in Ramda: | |
var compose = R.compose = function() { // TODO: type check of arguments? | |
var fns = slice(arguments); | |
return function() { | |
return foldr(function(fn, args) {return [fn.apply(this, args)];}, slice(arguments), fns)[0]; | |
}; | |
}; | |
//... | |
var useWith = R.useWith = _(function(fn /*, tranformers */) { |
OlderNewer