DEV Community

Cover image for Curry And Composition Function in JavaScript
Slim Coder
Slim Coder

Posted on

1 2

Curry And Composition Function in JavaScript


In this article i will discuss about:

  1. Higher Order Function

  2. Curry Function

  3. Composite Function

1) Higher Order Function

Higher-order functions are regular functions that do one or both of the following:

  1. Takes one or many functions as arguments

  2. Returns a function

Let’s look at simple example.

const c = b => b ;

add(a,b) => a+b; // here b is a function

add(3,c(3)) ;

2) Function Curry

A curried function is a function which takes multiple parameters one at a time, by taking the first argument, and returning a series of functions which each take the next argument until all the parameters have been fixed, and the function application can complete, at which point, the resulting value is returned.

const add = a => b => a + b;

const result = add(2)(3); // 5

3) Composite Function

Curried functions are particularly useful in the context of function composition.

In terms of algebra :

g: a -> b
f: b -> c

Suppose :

h: a -> c
h = f . g = f(g(x))

// Algebra definition, borrowing the . composition operator

In JavaScript :

const g = n => n + 1;

const f = n => n * 2;

const h = x => f(g(x));

h(2); // 6

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

Image of PulumiUP 2025

Let's talk about the current state of cloud and IaC, platform engineering, and security.

Dive into the stories and experiences of innovators and experts, from Startup Founders to Industry Leaders at PulumiUP 2025.

Register Now

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay