function partial(fun /*, pargs */){
var pargs = _.rest(arguments);
return function(/* arguments */){
var args = cat(pargs, _.toArray(arguments));
return fun.apply(fun, args);
} }
Recursion
trampoline(避免mutual-recursive溢出):
function even(n){ if(n==0) return true; else return partial1(odd, n-1); }
==> odd(20000001)()()...();
function trampoline(fun /*, args */){
var result = fun.apply(fun, _.rest(arguments)); //又来了
while(_.isFunction(result)) result = result();
return result; }
generator(惰性无限序列)
head-tail()抽象,其中,tail封装了“剩余序列的计算”
function genTake(n, gen){
var doTake = function(x, g, ret){ if(x==0)return ret; else return partial(doTake, x-1, genTail(g), cat(ret, genHead(g)));}
return trampoline(doTake, n, gen, []);
Purity, Immutability and Policies for Change
Object#freeze => deepFreeze
API:让对象修改方法返回新对象实例
Flow-based Programming
_.chain
LazyChain
thunk:a function waiting to be called
#force()
jQuery $.Deferred()
Pipelining
Action(Monad):flowing in context?
lift
actions
Programming without Class
Mixins
var polyToString = dispatch( function(s){ return _.isString(s)? s : undefined; }, ...