source: Dev/trunk/src/client/dojox/lang/functional/util.js @ 483

Last change on this file since 483 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 1.4 KB
Line 
1dojo.provide("dojox.lang.functional.util");
2
3dojo.require("dojox.lang.functional.lambda");
4
5// This module provides helpers:
6//      - inlining string lambda functions.
7
8(function(){
9        var df = dojox.lang.functional;
10
11        dojo.mixin(df, {
12                inlineLambda: function(/*String*/ lambda, /*String|Array*/ init, /*Function?*/ add2dict){
13                        // summary:
14                        //              Creates the inlined version of a string lambda.
15                        // lambda:
16                        //              The String variable representing the lambda function.
17                        // init:
18                        //              Conveys how to initialize parameters. If it is a String, then the apply() method
19                        //              would be emulated treating "init" as a list of input parameters.
20                        //              It it is an Array, then the call() method is emulated treating array members
21                        //              as input parameters.
22                        // add2dict:
23                        //              The optional function, which is used to record names of lambda parameters.
24                        //              If supplied, this function is called with a name of every parameter.
25
26                        var s = df.rawLambda(lambda);
27                        if(add2dict){
28                                df.forEach(s.args, add2dict);
29                        }
30                        var ap = typeof init == "string",       // apply or call?
31                                n = ap ? s.args.length : Math.min(s.args.length, init.length),
32                                a = new Array(4 * n + 4), i, j = 1;
33                        for(i = 0; i < n; ++i){
34                                a[j++] = s.args[i];
35                                a[j++] = "=";
36                                a[j++] = ap ? init + "[" + i + "]": init[i];
37                                a[j++] = ",";
38                        }
39                        a[0] = "(";
40                        a[j++] = "(";
41                        a[j++] = s.body;
42                        a[j] = "))";
43                        return a.join("");      // String
44                }
45        });
46})();
Note: See TracBrowser for help on using the repository browser.