Permalink
Browse files

added IEnumerable.js from firebug paste

  • Loading branch information...
1 parent 07a9e49 commit 8e008684cc29228d0ee594fc2717d3cb4d669f70 @Marak committed May 7, 2010
Showing with 41 additions and 0 deletions.
  1. +41 −0 lib/IEnumerable.js
View
@@ -0,0 +1,41 @@
+
+//(function() {
+ var IEnumerable = function(dataItems) {
+ if (!(this instanceof IEnumerable)) {
+ return new IEnumerable(dataItems);
+ }
+
+ this.clauses = new Array();
+ this.source = dataItems;
+ };
+
+
+ IEnumerable.prototype = {
+ getNext : function() {
+ var next;
+
+ var clauses = this.clauses;
+ this.source.some(function (element, index, array) {
+ if(clauses[0](element, index, array)) { // Generic predicate
+ next = element;
+ return true;
+ }
+ return false;
+ });
+
+ return next;
+ },
+
+ push: function(clause) {
+ this.clauses.push(clause);
+ return this;
+ }
+ };
+//})();
+
+
+console.log(IEnumerable([2, 3, 5])
+ .push(function (element, index, array) {
+ return index > 1 ? true : false;
+ })
+ .getNext());

0 comments on commit 8e00868

Please sign in to comment.