aboutsummaryrefslogtreecommitdiff
path: root/lib/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js52
1 files changed, 15 insertions, 37 deletions
diff --git a/lib/utils.js b/lib/utils.js
index 8ae17304..2f5a4866 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -112,51 +112,29 @@ function return_this() { return this; }
function return_null() { return null; }
var List = (function() {
- function List(a, f, backwards) {
- var ret = [], top = [], i;
- function doit() {
+ function List(a, f) {
+ var ret = [];
+ for (var i = 0; i < a.length; i++) {
var val = f(a[i], i);
- var is_last = val instanceof Last;
- if (is_last) val = val.v;
- if (val instanceof AtTop) {
- val = val.v;
- if (val instanceof Splice) {
- top.push.apply(top, backwards ? val.v.slice().reverse() : val.v);
- } else {
- top.push(val);
- }
- } else if (val !== skip) {
- if (val instanceof Splice) {
- ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v);
- } else {
- ret.push(val);
- }
- }
- return is_last;
- }
- if (Array.isArray(a)) {
- if (backwards) {
- for (i = a.length; --i >= 0;) if (doit()) break;
- ret.reverse();
- top.reverse();
+ if (val === skip) continue;
+ if (val instanceof Splice) {
+ ret.push.apply(ret, val.v);
} else {
- for (i = 0; i < a.length; ++i) if (doit()) break;
+ ret.push(val);
}
- } else {
- for (i in a) if (HOP(a, i)) if (doit()) break;
}
- return top.concat(ret);
+ return ret;
}
List.is_op = function(val) {
- return val === skip || val instanceof AtTop || val instanceof Last || val instanceof Splice;
+ return val === skip || val instanceof Splice;
+ };
+ List.splice = function(val) {
+ return new Splice(val);
};
- List.at_top = function(val) { return new AtTop(val); };
- List.splice = function(val) { return new Splice(val); };
- List.last = function(val) { return new Last(val); };
var skip = List.skip = {};
- function AtTop(val) { this.v = val; }
- function Splice(val) { this.v = val; }
- function Last(val) { this.v = val; }
+ function Splice(val) {
+ this.v = val;
+ }
return List;
})();