Member-only story

Javascript- Currying VS Partial Application

Deepak Gupta
TDS Archive
Published in
4 min readJul 22, 2018

A lot of people get confused in between currying and partial application and many of us do not know what, where and when we should use them. So this post will cover the practical usage and difference in them.

So lets' start with definitions.

Currying

Photo by Caroline Attwood on Unsplash

Is a technique for converting function calls with N arguments into chains of N function calls with a single argument for each function call?

Currying always returns another function with only one argument until all of the arguments have been applied. So, we just keep calling the returned function until we’ve exhausted all the arguments and the final value gets returned.

// Normal function
function addition(x, y) {
return x + y;
}
// Curried function
function addition(x) {
return function(y) {
return x + y;
}
}

Note: Curry takes a binary function and returns a unary function that returns a unary function. Its JavaScript code is

function curry(f) {
return function(x) {
return function(y) {
return f(x, y);
}
}
}

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Deepak Gupta
Deepak Gupta

Written by Deepak Gupta

COO @Steer Protocol| Write about Blockchain & Javascript | Take it easy

Responses (10)