Last change
on this file since 256 was
256,
checked in by hendrikvanantwerpen, 13 years ago
|
Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).
|
-
Property svn:executable set to
*
|
File size:
1.2 KB
|
Line | |
---|
1 | define(["dojo/_base/lang", "./lambda"], function(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 | /*===== |
---|
13 | var df = dojox.lang.functional; |
---|
14 | =====*/ |
---|
15 | |
---|
16 | lang.mixin(df, { |
---|
17 | // sequence generators |
---|
18 | repeat: function(/*Number*/ n, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){ |
---|
19 | // summary: builds an array by repeatedly applying a unary function N times |
---|
20 | // with a seed value Z. N should be greater than 0. |
---|
21 | o = o || dojo.global; f = df.lambda(f); |
---|
22 | var t = new Array(n), i = 1; |
---|
23 | t[0] = z; |
---|
24 | for(; i < n; t[i] = z = f.call(o, z), ++i); |
---|
25 | return t; // Array |
---|
26 | }, |
---|
27 | until: function(/*Function|String|Array*/ pr, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){ |
---|
28 | // summary: builds an array by repeatedly applying a unary function with |
---|
29 | // a seed value Z until the predicate is satisfied. |
---|
30 | o = o || dojo.global; f = df.lambda(f); pr = df.lambda(pr); |
---|
31 | var t = []; |
---|
32 | for(; !pr.call(o, z); t.push(z), z = f.call(o, z)); |
---|
33 | return t; // Array |
---|
34 | } |
---|
35 | }); |
---|
36 | |
---|
37 | return df; |
---|
38 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.