On Dec 13, 2:34 pm, "Arnar Birgisson" <[email protected]> wrote:
> Hi,
>
> On Fri, Dec 12, 2008 at 21:46, Eoghan <[email protected]> wrote:
> > After consideration of generalisation, maybe what I'm looking for is a
> > version of `partial` that can take out of order arguments, something
> > along the following lines:
>
> >    forEach($$('#my-ul li'), partial(connect,
> > MochiKit.Base.placeholder, 'onclick', function(e){
> >                 // do sumn'
> >            }));
>
> > Although I'm not sure what the implementation of partial would look
> > like in order to support out of order placeholder arguments...
>
> Ah, yes - I have *often* felt the need for this. Here is one possible
> implementation:
>
> function p() {
>    var args = Array.prototype.slice.call(arguments);
>    appendChildNodes('logpane', DIV(null, args.join(', ')));
>
> }
>
> var _ = new Object();
>
> var invalidNumberOfArgs = new Error("Number of given arguments does
> not match number of unknown arguments.");
>
> function partial() {
>    var args = Array.prototype.slice.call(arguments);
>    var f = args.shift();
>    var unknowns = filter(MochiKit.Base.partial(operator.seq, _), args).length;
>    return function() {
>        if (arguments.length != unknowns) {
>            throw invaldNumberOfArgs;
>        }
>        var passed = Array.prototype.slice.call(arguments);
>        var filled = map(function (a) {
>            if (a === _) {
>                return passed.shift();
>            } else {
>                return a;
>            }
>        }, args);
>        return f.apply(this, filled);
>    }
>
> }
>
> function test() {
>    p('start');
>
>    var x = partial(p, "one", _, "three");
>    x('two');
>
>    x = partial(p, _, _, "three", _);
>    x('one', 'two', 'four');
>
>    p('done');
>
> }
>
> addLoadEvent(test);
>
> As for permuting arguments, I have some ideas.. let me think about them a bit.
>
> cheers,
> Arnar

Very nice, I thought to implement this myself but baulked.
May I suggest MochiKit.Base.__  as the name of the placeholder
variable.
I can't imagine needing the permuting version myself.

Eoghan
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to