Syntax is sort of similar to what we use in BeyondJS.
To bind argument 'goo' of the function 'bar' in put the new function in variable 'foo':
var foo = bar.curry({goo : "hello world"});
If goo happens to be the first argument you can also write:
var foo = bar.curry("hello world");
and if it happens to be the last argument:
var foo = bar.curry({-1 : "hello world"});
Binding to the second argument:
var foo = bar.curry({2 : "hello world"});
Or, you can use the fact that curry() also accepts an array as the list of values to bind to so you write:
var foo = bar.curry([,"hello world"]);
The first array element in this case is empty so its not bound to.
Binding to several arguments can be done as:
var foo = bar.curry("hello").curry("world");
or simply:
var foo = bar.curry("hello", "world");
In addition we also provide the using() method which is similar to curry() but handles binding of functions differently. If bar and goo are functions:
var foo = bar.curry(goo);
binds a reference to the function goo to the first argument. OTOH:
var foo = bar.using(goo);
binds an invocation of the function goo to this first argument. That is, whenever foo is called, goo is also called automatically and its return value is assigned to bar's first argument.
Finally writing:
var foo = bar.andThen(goo);
is equivalent to writing:
var foo = goo.using(bar);
First bar is activated and then its return value is passed along to go.
|