This AI is still in early stages of development.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Overview

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

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

Where fExisting is any existing function.

Parameters

ParameterTypeMandatoryDescriptionUtil.js version
cArgsOne or more arguments(tick)One or more arguments that will be passed in to fExisting when you access it via fNew0.5

Return value

ValueTypeDescriptionUtil.js version
<fNew>FunctionA new function which will automatically set the cArgs arguments for fExisting and then append any additional arguments passed in to fNew.0.5
<fExisting>FunctionIf you do not specify cArgs then the existing function will be returned.0.5

Example

function booler(not,a,b) {
  return (not) ? a!=b : a==b;
}
var isMe = booler.uCurry(false,me); // not == false, a = me
isMe(7); // true if me == 7, false if me != 7
 
var isNotMe = booler.uCurry(true,me);
isMe(7); // true if me != 7, false if me == 7

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

See also

  • uCompose – create a new function by merging two existing functions
  • Curry – I based my uCurry function on code samples from this blog.
  • No labels