Using underscore for an any() function.

This commit is contained in:
Jeremy Ashkenas
2010-02-13 02:29:37 -05:00
parent e6a53bd852
commit 1ab3b183a8
2 changed files with 5 additions and 23 deletions

View File

@@ -1,7 +1,8 @@
(function(){
var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, Node, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThisNode, ThrowNode, TryNode, ValueNode, WhileNode, any, compact, del, dup, flatten, inherit, merge, statement;
var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, Node, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThisNode, ThrowNode, TryNode, ValueNode, WhileNode, _, compact, del, dup, flatten, inherit, merge, statement;
var __hasProp = Object.prototype.hasOwnProperty;
process.mixin(require('./scope'));
_ = require('./underscore')._;
// Some helper functions
// Tabs are two spaces for pretty printing.
TAB = ' ';
@@ -77,21 +78,6 @@
}
return fresh;
};
// Do any of the elements in the list pass a truth test?
any = function any(list, test) {
var __a, __b, __c, item, result;
result = (function() {
__a = []; __b = list;
for (__c = 0; __c < __b.length; __c++) {
item = __b[__c];
if (test(item)) {
__a.push(true);
}
}
return __a;
}).call(this);
return !!result.length;
};
// Delete a key from an object, returning the value.
del = function del(obj, key) {
var val;
@@ -457,7 +443,7 @@
// Compile a vanilla function call.
compile_node: function compile_node(o) {
var __a, __b, __c, arg, args;
if (any(this.args, function(a) {
if (_.any(this.args, function(a) {
return a instanceof SplatNode;
})) {
return this.compile_splat(o);