function internalCompose(f, g) {
return function() {
return f.call(this, g.apply(this, arguments));
};
}
var compose = R.compose = function() {
var length = arguments.length, func = arguments[--length];
if (!length) {
return partially(compose, func);
}
while (length--) {
func = internalCompose(arguments[length], func);
}
return func;
};
R.pipe = function() {
if (arguments.length == 1) {
return partially (R.pipe, arguments[0]);
}
return compose.apply(this, _slice(arguments).reverse());
};
aliasFor("pipe").is("sequence");
var flip = R.flip = function (fn) {
return function (a, b) {
return arguments.length < 2 ?
function(b) { return fn.apply(this, [b, a].concat(_slice(arguments, 1))); } :
fn.apply(this, [b, a].concat(_slice(arguments, 2)));
};
};
R.lPartial = function (fn ) {
var args = _slice(arguments, 1);
return arity(Math.max(fn.length - args.length, 0), function () {
return fn.apply(this, concat(args, arguments));
});
};
aliasFor("lPartial").is("applyLeft");
R.rPartial = function (fn) {
var args = _slice(arguments, 1);
return arity(Math.max(fn.length - args.length, 0), function() {
return fn.apply(this, concat(arguments, args));
});
};
aliasFor("rPartial").is("applyRight");
R.memoize = function (fn) {
var cache = {};
return function () {
var position = foldl(function (cache, arg) {
return cache[arg] || (cache[arg] = {});
}, cache,
_slice(arguments, 0, arguments.length - 1));
var arg = arguments[arguments.length - 1];
return (position[arg] || (position[arg] = fn.apply(this, arguments)));
};
};
R.once = function (fn) {
var called = false, result;
return function () {
if (called) {
return result;
}
called = true;
result = fn.apply(this, arguments);
return result;
};
};
R.wrap = function(fn, wrapper) {
return function() {
return wrapper.apply(this, concat([fn], arguments));
};
};
R.construct = function (Fn) {
var f = function () {
var obj = new Fn();
Fn.apply(obj, arguments);
return obj;
};
return Fn.length > 1 ? curry(nAry(Fn.length, f)) : f;
};
R.fork = function (after) {
var fns = _slice(arguments, 1);
return function () {
var args = arguments;
return after.apply(this, map(function (fn) {
return fn.apply(this, args);
}, fns));
};
};