Currying in JavaScript

function volume( l, w, h ) {
return l * w * h;
}
var curried = curry( volume );curried( 1 )( 2 )( 3 ); // 6

Disclaimer

Writing our curry function

function curry( fn ) {}
function curry( fn ) {
var arity = fn.length;
}
function curry( fn ) {
var arity = fn.length;
return (function resolver() {

}());
}
function curry( fn ) {
var arity = fn.length;
return (function resolver() {
var memory = Array.prototype.slice.call( arguments );
}());
}
function curry( fn ) {
var arity = fn.length;
return (function resolver() {
var memory = Array.prototype.slice.call( arguments );
return function() {
};
}());
}
function curry( fn ) {
var arity = fn.length;
return (function resolver() {
var memory = Array.prototype.slice.call( arguments );
return function() {
var local = memory.slice();
};
}());
}
function curry( fn ) {
var arity = fn.length;
return (function resolver() {
var memory = Array.prototype.slice.call( arguments );
return function() {
var local = memory.slice();
Array.prototype.push.apply( local, arguments );
};
}());
}
function curry( fn ) {
var arity = fn.length;
return (function resolver() {
var memory = Array.prototype.slice.call( arguments );
return function() {
var local = memory.slice(), next;
Array.prototype.push.apply( local, arguments );
next = local.length >= arity ? fn : resolver;
return next.apply( null, local );
};
}());
}
function volume( l, w, h ) {
return l * w * h;
}
var curried = curry( volume );
function volume( l, w, h ) {
return l * w * h;
}
var curried = curry( volume );
var length = curried( 2 );
function volume( l, w, h ) {
return l * w * h;
}
var curried = curry( volume );
var length = curried( 2 );
var lengthAndWidth = length( 3 );
function volume( l, w, h ) {
return l * w * h;
}
var curried = curry( volume );
var length = curried( 2 );
var lengthAndWidth = length( 3 );
console.log( lengthAndWidth( 4 ) ); // 24

Wrapping up

--

--

--

Director of Engineer and founding team member @StarryInternet. Formerly @Aereo. @kevincennis on Twitter and Github. http://kevvv.in

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin Ennis

Kevin Ennis

Director of Engineer and founding team member @StarryInternet. Formerly @Aereo. @kevincennis on Twitter and Github. http://kevvv.in

More from Medium

Currying in JavaScript

padEnd() JavaScript

Creating a Javascript Promise

Destructuring Arrays in JavaScript