Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

naming convention for the first function in curried functions

Is there a name convention if it comes to curried function like this:

const someName = argA => argB => ...
const newFunction = someName(someArg)

is there any convention for naming the declaration of someName? like prefixing it with init / create etc?

like image 240
Marcin Avatar asked Oct 27 '19 19:10

Marcin


People also ask

How do you call a currying function?

Currying is a function that takes one argument at a time and returns a new function expecting the next argument. It is a transformation of functions that translates a function from callable as f(a, b, c) into callable as f(a)(b)(c).

What is curried function in functional programming?

Currying is the transformation of a function with multiple arguments into a sequence of single-argument functions. That means converting a function like this f(a, b, c, ...) into a function like this f(a)(b)(c)... . If you know Python's functools. partial , then this is very similar to it.

Are curried functions higher-order?

Higher-order functions are functions that take functions as parameters or return functions when called. Curried functions are higher-order functions that take one argument at a time returning a series of functions until all parameters are passed.

Which of the following is a curried function?

A curried function is a function of several arguments rewritten such that it accepts the first argument and returns a function that accepts the second argument and so on. This allows functions of several arguments to have some of their initial arguments partially applied.


1 Answers

You could take a descriptive naming, like

const
    multiplyBy = a => b => a * b,
    multiplyWith5 = multiplyBy(5);

var array = [3, 14],
    result = array.map(multiplyWith5);
like image 197
Nina Scholz Avatar answered Oct 02 '22 17:10

Nina Scholz