Changeset 13
- Timestamp:
- 10/25/05 17:12:31 (3 years ago)
- Files:
-
- jsolait/trunk/jsolait/lib/iter.js (modified) (2 diffs)
- jsolait/trunk/jsolait/lib/lang.js (modified) (1 diff)
- jsolait/trunk/jsolait/lib/sets.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
jsolait/trunk/jsolait/lib/iter.js
r5 r13 20 20 /** 21 21 Iterator module providing iteration services. 22 There are two main functions iter and fora for iterating over iterable objects.23 An iterable object is an object which has an iterator function which returns an Iterator object.24 iter iterates over the object synchronously calling a callback for each item.25 fora does the same but in an asynchronous matter.22 There is one global function iter() which can be used to iterate over iterable objects synchronously or 23 if given a callback asynchronously. 24 An iterable object is an object which has an iterator function (__iter__) which returns an Iterator object. 25 26 26 The Range class is there to create an iterable object over a range of numbers. 27 27 28 @creator Jan-Klaas Kollhof 28 29 @created 2004-12-08 … … 377 378 print("for on Array + iter \t" + testing.timeExec(100,function(){ 378 379 var s=''; 379 for( var item= (i=r.__iter__()).next(); item!==undefined; item=i.next()){380 for(i=r.__iter__(); item=i.next() !==undefined;){ 380 381 s+= item; 381 382 task(); jsolait/trunk/jsolait/lib/lang.js
r10 r13 35 35 var rs=startEndChar; 36 36 var p= s.indexOf(startEndChar); 37 while(p >= 0){ 37 while(p >= 0){ 38 38 if(s.charAt(p-1) == "\\"){ 39 39 rs+=s.slice(0,p+1); jsolait/trunk/jsolait/lib/sets.js
r9 r13 21 21 /** 22 22 A module providing Sets. 23 23 24 @creator Jan-Klaas Kollhof 24 25 @created 2005-03-11 … … 43 44 }); 44 45 46 /** 47 The Set class. 48 Items in a class must be Strings, Numbers, Objects that return a unique string representation or 49 Objects implementing a __hash__ method. (All objects created from jsolait classes have a __hash__ function. 50 **/ 45 51 mod.Set=Class(function(publ, supr){ 46 52 /** 47 53 Initializes a Set instance. 48 @param itearatable=[] A String or an Array of which the elements will be added to the set. 49 **/ 50 publ.__init__=function(iterable){ 54 @param elem* An element which is added to the set or an Array, String or iterable object of which the elements are added to the set. 55 **/ 56 publ.__init__=function(elem){ 57 51 58 this.items = {}; 52 if(iterable === undefined){ 53 iterable = []; 54 } 55 if(iterable.constructor == String){ 56 iterable = iterable.split(""); 57 } 58 //todo do iterable impl 59 /* 60 if(iterable.__iter__){ 61 var i=iterable.__iter__(); 62 var item; 63 while(item=i.next()!==undefined){ 64 this.add(item); 65 } 66 }else{*/ 67 for(var i=0;i<iterable.length;i++){ 68 this.add(iterable[i]); 69 } 70 //} 59 var elems =[]; 60 61 if(arguments.length > 1){ 62 elems=arguments; 63 }else if(arguments.length == 1){ 64 elems = arguments[0]; 65 if(elems instanceof Array){ 66 }else if(typeof elems == "string"){ 67 elems=elems.split(""); 68 }else if(elems.__iter__){ 69 var i=iterable.__iter__(); 70 var item; 71 while(item=i.next()!==undefined){ 72 this.add(item); 73 } 74 return; 75 }else{ 76 throw new mod.Exception("Array,String or iterable object expected but found %s".format(elems)); 77 } 78 } 79 80 for(var i=0;i<elems.length;i++){ 81 this.add(elems[i]); 82 } 71 83 }; 72 84 … … 223 235 return ns; 224 236 }; 237 225 238 226 239 /**
