Closed ghost closed 9 years ago
I need to put an argument last so I put together a simple swap function. Could you please help me understand why this don't work?
curry = require('curry'); function swap(fn, i1, i2) { return function() { var args = Array.prototype.slice.call(arguments); var t = args[i1]; args[i1] = args[i2]; args[i2] = t; console.log(args); // for testing purposes return fn.apply(null, args); } } function sub(a,b) {return a-b} console.log(sub(3,2)); console.log( swap(sub, 0, 1)(3,2) ); console.log( curry(sub)(3)(2) ); // Error console.log( curry(swap(sub, 0, 1)) (3)(2) );
Any help is greatly appreciated!
I realized that curry don't work with functions where the arguments are implicit. curry.to needs to be used.
curry.to
I need to put an argument last so I put together a simple swap function. Could you please help me understand why this don't work?
Any help is greatly appreciated!