---
title: "Currying in ES6"
description: "Implementing function currying with ES6 arrow functions. Practical notes and code examples on Currying in ES6 by Hemanth HM."
url: "https://h3manth.com/scribe/currying-in-es6/"
canonical_url: "https://h3manth.com/scribe/currying-in-es6/"
markdown_url: "https://h3manth.com/scribe/blog/currying-in-es6.md"
publishDate: "2015-04-30T00:00:00.000Z"
author: "Hemanth HM"
category: "javascript"
tags: ["javascript","es6","functional"]
word_count: 129
reading_time_minutes: 1
x_markdown_tokens: 298
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Currying in ES6

> Implementing function currying with ES6 arrow functions. Practical notes and code examples on Currying in ES6 by Hemanth HM.

Currying breaks down a function that receives multiple arguments into a series of functions that each receive part of the arguments.

Named after Haskell Curry, if we have `f::(x, y) -> z`, when curried we get `curry(f) :: x -> y -> z`.

## ES6 Implementation

```javascript
let curry1 = f => (a) => f(a);

let curry2 = f => (...a) => (...b) => f(...a, ...b);

let curry3 = f => (...a) => (...b) => (...c) => f(...a, ...b, ...c);

## nCurry for Any Arity
javascript
let nCurry = n => (f, ...args) => {
  return function(...nargs) {
    let combinedArgs = args.concat(nargs);
    if (combinedArgs.length < n) {
      combinedArgs.unshift(f);
      return nCurry(n).apply(null, combinedArgs);
    }
    return f.apply(null, combinedArgs);
  };
};

// Usage: nCurry(4)(listify)(1)(2)(3)(4); // [1,2,3,4]
```

Hope you enjoyed your curry! 🍛
