Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save miguelfrias/a3081cfe0cfb2156367912d850ea966b to your computer and use it in GitHub Desktop.
Save miguelfrias/a3081cfe0cfb2156367912d850ea966b to your computer and use it in GitHub Desktop.
(function() {
'use strict';
function revocable(func1) {
return {
invoke: function(a) {
return func1.apply(
this,
arguments
);
},
revoke: function() {
func1 = null;
}
};
}
function counterf(a) {
return {
inc: function() {
return a + 1;
},
dec: function() {
return a - 1;
}
};
}
function once(func1) {
return function() {
var f = func1;
func = null;
return f.apply(
this,
arguments
);
};
}
function composeb(func1 , func2) {
return function(a, b, c) {
return func2(
func1(a, b),
c
);
};
}
function composeu(func1, func2) {
return function(y) {
return func2(
func1(y)
);
};
}
function twice(binary) {
return function(y) {
return binary(y, y);
};
}
function demethodize(func) {
return function(that, y) {
return func.call(that, y);
};
}
function methodize(func) {
return function(y) {
return func(this, y);
};
}
var inc = curry(add, 1);
function curry(func, x) {
// Solution 1
// return function(y) {
// return func(x, y);
// };
// Solution 2
return applyf(func)(first);
}
function applyf(binary) {
return function (x) {
return function (y) {
return binary(x, y);
};
};
}
function addf(x) {
return function(y) {
return x + y;
};
}
function identityf(x) {
return function() {
return x;
};
}
function mul(a, b) {
return a * b;
}
function add(a, b) {
return a + b;
}
function identity(x) {
return x;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment