Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Overview

Excerpt

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

...

For more info on currying, see Wikipedia.

Availability

Util.js v0.5 and above.

Syntax

Code Block
var fNew = fExisting.uCurry(cArgs);
 
fNew(args);

Where fExisting is any existing function.

Parameters

...

 

Syntax

Code Block
themeRDark
languagejavascript
linenumberstrue
// 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 / FunctionTypeMandatoryDescription

...

API 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

ValueTypeDescription

...

API 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

Code Block
themeRDark
languagejavascript
titlePredefining first param to a number...
linenumberstrue
function 

...

add(

...

a, b) {
  return 

...

a

...

 

...

+ 

...

b;
}
 
var 

...

Add5To = 

...

add.

...

curry(

...

5); // 

...

parameter "a" is pre-defined with value 5
 
Add5To(10); // 

...

15 

...

A good example is shown in Object.uAddProperty() example using a curried allianceExistsBetween() function.

See also

...

(parameter "a" already set to 5, "b" set to 10)
Div
classbox
Availability
Status
colourGreen
titleStable

Requires:

Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

Function Manipulation

Topics:

Child pages (Children Display)
alltrue
depthall
pageFunction Manipulation
excerpttrue

Div
classbox

See Also

Related pages: