0% found this document useful (0 votes)
19 views1 page

What Is A Higher Order Function

The document defines higher order functions as functions that accept or return other functions, unary functions as functions that accept exactly one argument, and currying functions as turning functions with multiple arguments into sequences of functions with a single argument through partial application.

Uploaded by

Aswathy R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

What Is A Higher Order Function

The document defines higher order functions as functions that accept or return other functions, unary functions as functions that accept exactly one argument, and currying functions as turning functions with multiple arguments into sequences of functions with a single argument through partial application.

Uploaded by

Aswathy R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

What is a higher order function

Higher-order function is a function that accepts another function as an


argument or returns a function as a return value or both.

const firstOrderFunc = () => console.log ('Hello, I am a First order


function');
const higherOrder = ReturnFirstOrderFunc => ReturnFirstOrderFunc();
higherOrder(firstOrderFunc);

2. What is a unary function

Unary function (i.e. monadic) is a function that accepts exactly one


argument. It stands for a single argument accepted by a function.

Let us take an example of unary function,

const unaryFunction = a => console.log (a + 10); // Add 10 to the given


argument and display the value

3. What is the currying function

Currying is the process of taking a function with multiple arguments and


turning it into a sequence of functions each with only a single argument.
Currying is named after a mathematician Haskell Curry. By applying
currying, a n-ary function turns it into a unary function.

Let's take an example of n-ary function and how it turns into a currying
function,

const multiArgFunction = (a, b, c) => a + b + c;


console.log(multiArgFunction(1,2,3));// 6

const curryUnaryFunction = a => b => c => a + b + c;


curryUnaryFunction (1); // returns a function: b => c => 1 + b + c
curryUnaryFunction (1) (2); // returns a function: c => 3 + c
curryUnaryFunction (1) (2) (3); // returns the number 6
Curried functions are great to improve code reusability and functional
composition

You might also like