On May 18, 2006, at 10:54 AM, Arnar Birgisson wrote:
>
> On 5/18/06, Arnar Birgisson <[EMAIL PROTECTED]> wrote:
>> Think of composition as a pipeline of functions: compose(f1, f2, ...,
>> fN) returns a function that puts it argument backwards through the
>> pipline, applying fN, then fN-1 to the result etc.
>
> Sorry, correction: it doesn't go backwards, it goes forward.
> compose(f1, f2, ..., fN)(x) == f1(f2(...fN(x)...))
Still looks backwards to me, because fN(x) gets evaluated first.
r1 = fN(x)
r2 = fN-1(r1)
..
rN = f1(rN-1)
Also,
compose(f1, f2, .., fN) == compose(f1, compose(f2, ... fN)) and so on
I guess an implementation would look something like this:
compose = function () {
var fnlist = [];
for (var i = 0; i < arguments.length; i++) {
fnlist.push(arguments[i]);
}
return function () {
var args = arguments;
for (var i = fnlist.length; i >= 0; i--) {
args = [fnlist[i].apply(this, args)];
}
return args[0];
};
}
-bob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---