summaryrefslogtreecommitdiff
path: root/js/dojo/dojox/lang/functional/sequence.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/dojo/dojox/lang/functional/sequence.js')
-rw-r--r--js/dojo/dojox/lang/functional/sequence.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/js/dojo/dojox/lang/functional/sequence.js b/js/dojo/dojox/lang/functional/sequence.js
new file mode 100644
index 0000000..3ba4d9e
--- /dev/null
+++ b/js/dojo/dojox/lang/functional/sequence.js
@@ -0,0 +1,39 @@
+//>>built
+define("dojox/lang/functional/sequence", ["dojo/_base/lang", "./lambda"], function(lang, df){
+
+// This module adds high-level functions and related constructs:
+// - sequence generators
+
+// If you want more general sequence builders check out listcomp.js and
+// unfold() (in fold.js).
+
+// Defined methods:
+// - take any valid lambda argument as the functional argument
+
+/*=====
+ var df = dojox.lang.functional;
+ =====*/
+
+ lang.mixin(df, {
+ // sequence generators
+ repeat: function(/*Number*/ n, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){
+ // summary: builds an array by repeatedly applying a unary function N times
+ // with a seed value Z. N should be greater than 0.
+ o = o || dojo.global; f = df.lambda(f);
+ var t = new Array(n), i = 1;
+ t[0] = z;
+ for(; i < n; t[i] = z = f.call(o, z), ++i);
+ return t; // Array
+ },
+ until: function(/*Function|String|Array*/ pr, /*Function|String|Array*/ f, /*Object*/ z, /*Object?*/ o){
+ // summary: builds an array by repeatedly applying a unary function with
+ // a seed value Z until the predicate is satisfied.
+ o = o || dojo.global; f = df.lambda(f); pr = df.lambda(pr);
+ var t = [];
+ for(; !pr.call(o, z); t.push(z), z = f.call(o, z));
+ return t; // Array
+ }
+ });
+
+ return df;
+});