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?
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).
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.
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.
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.
You could take a descriptive naming, like
const
multiplyBy = a => b => a * b,
multiplyWith5 = multiplyBy(5);
var array = [3, 14],
result = array.map(multiplyWith5);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With