Skip to content

Instantly share code, notes, and snippets.

@lupuszr
Last active February 17, 2016 15:36
Show Gist options
  • Save lupuszr/e61df6bae6ec0bf2040d to your computer and use it in GitHub Desktop.
Save lupuszr/e61df6bae6ec0bf2040d to your computer and use it in GitHub Desktop.
//implementation
//compose, curry, partial
var compose = curry(function(f, g, x) {
return f(g(x))
})
function curry(f) {
var length = f.length;
if (length > 0) return partial(f, length, []);
else return f; // f is already curried
}
function partial(f, length, a) {
return function () {
var count = arguments.length;
var arity = length;
var part = count < arity;
var size = part ? count : arity;
var args = new Array(size);
var index = 0;
while (index < size) args[index] = arguments[index++];
if (part) return partial(f, arity - count, a.concat(args));
var result = f.apply(null, a.concat(args));
if (typeof result === "function")
result = curry(result);
if (arity < count) {
var args = new Array(count - arity), number = 0;
while (index < count) args[number++] = arguments[index++];
return result.apply(null, args);
}
return result;
};
}
//reducer factory
export const hero = (dox,action,state) => dox[action]?dox[action](state):dox['default'](state)
//curriable reducer factory
export const reducerFactory = curry(hero)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment