diff options
Diffstat (limited to 'lib/utils.js')
-rw-r--r-- | lib/utils.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/utils.js b/lib/utils.js index e9a2f80a..6f8334ee 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -113,6 +113,8 @@ var MAP = (function(){ var ret = [], top = [], i; function doit() { var val = f.call(o, 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) { @@ -128,16 +130,23 @@ var MAP = (function(){ ret.push(val); } } + return is_last; }; - if (a instanceof Array) for (i = 0; i < a.length; ++i) doit(); - else for (i in a) if (HOP(a, i)) doit(); + if (a instanceof Array) { + for (i = 0; i < a.length; ++i) if (doit()) break; + } + else { + for (i in a) if (HOP(a, i)) if (doit()) break; + } return top.concat(ret); }; MAP.at_top = function(val) { return new AtTop(val) }; MAP.splice = function(val) { return new Splice(val) }; + MAP.last = function(val) { return new Last(val) }; var skip = MAP.skip = {}; function AtTop(val) { this.v = val }; function Splice(val) { this.v = val }; + function Last(val) { this.v = val }; return MAP; })(); |