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 where(matchThis) { | |
var keys = Object.keys(matchThis); | |
return function(testObj) { | |
var match = ramda.all(function(key) { | |
return testObj[key] === matchThis[key]; | |
}, keys); | |
return match ? testObj : false; | |
}; | |
} |
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
// solver | |
var R = require('ramda'); | |
function configure(isLeaf, isGoal, getChildren) { | |
return function recursiveSolve(node, sideEffects) { | |
return (isLeaf(node)) ? isGoal(node) && sideEffects(node): | |
R.any(function(child) { | |
sideEffects(child); | |
return recursiveSolve(child); | |
}, getChildren(node)); |
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
// Node.js CheatSheet. | |
// Download the Node.js source code or a pre-built installer for your platform, and start developing today. | |
// Download: http://nodejs.org/download/ | |
// More: http://nodejs.org/api/all.html | |
// 0. Synopsis. | |
// http://nodejs.org/api/synopsis.html | |
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 lazy(f) { | |
return function () { | |
var self = this, args = arguments; | |
return function () { | |
var data = f.apply(self, args); | |
return typeof data === "function" ? | |
data.apply(this, arguments) : data; | |
}; | |
}; |
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
var R = require('ramda'); | |
// cf. http://thecomputersarewinning.com/post/Transducers-Are-Fundamental/ | |
function inc(n) { | |
return n + 1; | |
} | |
function meanReducer(acc, x) { | |
var newAcc = {}; |
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 cond2() { | |
var cs = [].slice.call(arguments, 0, arguments.length - 1); | |
var ow = arguments[arguments.length - 1]; | |
return function() { | |
var i = -1; | |
while(++i < cs.length) { | |
var value = cs[i].apply(this, arguments); | |
if (value) { | |
return value; | |
} |
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
// run in ramda dir | |
var R = require('./ramda'); | |
var Maybe = require('./ext/types/Maybe'); | |
var ms = [Maybe(1), Maybe(2), Maybe(3)]; | |
R.commute(Maybe.of, ms); //=> Maybe([1, 2, 3]) i.e., Just [1, 2, 3] | |
// or just use constructor fn: | |
R.commute(Maybe, ms); //=> Maybe([1, 2, 3]) |
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
// fizzbuzz ramda-style | |
var R = require('ramda'); | |
R.forEach(R.cond( | |
[R.pipe(R.modulo(R.__, 15), R.eq(0)), function() { console.log('FizzBuzz'); }], | |
[R.pipe(R.modulo(R.__, 3), R.eq(0)), function() { console.log('Fizz'); }], | |
[R.pipe(R.modulo(R.__, 5), R.eq(0)), function() { console.log('Buzz'); }], | |
[R.alwaysTrue, function(){}] | |
), R.range(1, 101)); |
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; | |
}, []); | |
} |
OlderNewer