Last change
on this file was
483,
checked in by hendrikvanantwerpen, 11 years ago
|
Added Dojo 1.9.3 release.
|
-
Property svn:executable set to
*
|
File size:
1.2 KB
|
Rev | Line | |
---|
[483] | 1 | define(["dojo/_base/kernel", "dojo/_base/lang", "./lambda"], function(kernel, lang, df){ |
---|
| 2 | |
---|
| 3 | // This module adds high-level functions and related constructs: |
---|
| 4 | // - sequence generators |
---|
| 5 | |
---|
| 6 | // If you want more general sequence builders check out listcomp.js and |
---|
| 7 | // unfold() (in fold.js). |
---|
| 8 | |
---|
| 9 | // Defined methods: |
---|
| 10 | // - take any valid lambda argument as the functional argument |
---|
| 11 | |
---|
| 12 | lang.mixin(df, { |
---|
| 13 | // sequence generators |
---|
| 14 | repeat: function(/*Number*/ n, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){ |
---|
| 15 | // summary: |
---|
| 16 | // builds an array by repeatedly applying a unary function N times |
---|
| 17 | // with a seed value Z. N should be greater than 0. |
---|
| 18 | o = o || kernel.global; f = df.lambda(f); |
---|
| 19 | var t = new Array(n), i = 1; |
---|
| 20 | t[0] = z; |
---|
| 21 | for(; i < n; t[i] = z = f.call(o, z), ++i); |
---|
| 22 | return t; // Array |
---|
| 23 | }, |
---|
| 24 | until: function(/*Function|String|Array*/ pr, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){ |
---|
| 25 | // summary: |
---|
| 26 | // builds an array by repeatedly applying a unary function with |
---|
| 27 | // a seed value Z until the predicate is satisfied. |
---|
| 28 | o = o || kernel.global; f = df.lambda(f); pr = df.lambda(pr); |
---|
| 29 | var t = []; |
---|
| 30 | for(; !pr.call(o, z); t.push(z), z = f.call(o, z)); |
---|
| 31 | return t; // Array |
---|
| 32 | } |
---|
| 33 | }); |
---|
| 34 | |
---|
| 35 | return df; |
---|
| 36 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.