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
<!doctype html> | |
<html> | |
<head> | |
<style> | |
#wrapper { | |
height: 200px; | |
padding: 20px; | |
background-color: #ddeeff; | |
} | |
#vector { |
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
// assuming we have indexedDB | |
var version = 3; | |
var dbConn = indexedDB.open("db", version); | |
var db; | |
dbConn.onerror = function(e) { | |
console.log('error connecting to be'); | |
}; | |
dbConn.onsuccess = function(e) { |
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
/* | |
S : \x y z -> x z (y z) | |
*/ | |
// S :: (z -> (a -> b)) -> (z -> a) -> z -> b | |
function S(x, y, z) { | |
return x(z)(y(z)); | |
} | |
// example: | |
// add :: a -> a -> a |
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 */) { |
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; | |
}; |
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
(function(global) { | |
global.Functor = function(conf) { | |
Functor.types[conf.key] = { | |
obj: conf.obj, | |
fmap: conf.fmap | |
}; | |
}; | |
Functor.types = {}; |
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
/* | |
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
/* | |
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. | |
*/ |