(info) This AI is still in early stages of development.

function.curry()

Create a new function based on an existing function but with some parameters pre-defined.

 

Syntax

// create new function based on existing one with one or more pre-defined arguments
var newFn = existingFn.curry(args...);
 
// use the new function, optionally specifying additional arguments
var result = newFn(extraArgs...);

Parameters / Functions

Parameter / FunctionTypeMandatoryDescriptionAPI Version
existingFnFunction(tick)The original function1.0
args...One or more arguments(tick)

One or more arguments that will be passed in to existingFn when you access it via newFn

If you don't specify any arguments, .curry() will just return existingFn as there's no point in creating a curried function.

1.0
extraArgs...Additional arguments(question)Optionally pass in remaining arguments when calling newFn1.0

Return value

ValueTypeDescriptionAPI Version
<newFn>FunctionA new function which will automatically set the cArgs arguments for fExisting and then append any additional arguments passed in to fNew.1.0
<existingFn>FunctionIf you do not specify cArgs then the existing function will be returned.1.0
<result>VariantThe result of running newFn()1.0

Example

Predefining first param to a number...
function add(a, b) {
  return a + b;
}
 
var Add5To = add.curry(5); // parameter "a" is pre-defined with value 5
 
Add5To(10); // 15 (parameter "a" already set to 5, "b" set to 10)
Availability STABLE

Requires:

Contents

Jump to:

Function Manipulation

Topics:

  • function.wraps()Create a new function by wrapping an existing function in another existing function...
  • function.curry()Create a new function based on an existing function but with some parameters pre-defined.
  • n.times()Invoke a function n times...

See Also

Related pages: