Browse Source

Fixed issue #108

Nicolas Petton 13 years ago
parent
commit
785721b04f
3 changed files with 42 additions and 0 deletions
  1. 14 0
      js/Kernel-Collections.deploy.js
  2. 19 0
      js/Kernel-Collections.js
  3. 9 0
      st/Kernel-Collections.st

+ 14 - 0
js/Kernel-Collections.deploy.js

@@ -2514,6 +2514,20 @@ return self;}
 }),
 smalltalk.Set);
 
+smalltalk.addMethod(
+'_select_',
+smalltalk.method({
+selector: 'select:',
+fn: function (aBlock){
+var self=this;
+var collection=nil;
+collection=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []);
+smalltalk.send(self, "_do_", [(function(each){return ((($receiver = smalltalk.send(aBlock, "_value_", [each])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return smalltalk.send(collection, "_add_", [each]);})() : nil) : smalltalk.send($receiver, "_ifTrue_", [(function(){return smalltalk.send(collection, "_add_", [each]);})]));})]);
+return collection;
+return self;}
+}),
+smalltalk.Set);
+
 
 
 smalltalk.addClass('HashedCollection', smalltalk.Collection, [], 'Kernel-Collections');

+ 19 - 0
js/Kernel-Collections.js

@@ -3579,6 +3579,25 @@ referencedClasses: []
 }),
 smalltalk.Set);
 
+smalltalk.addMethod(
+unescape('_select_'),
+smalltalk.method({
+selector: unescape('select%3A'),
+category: 'enumerating',
+fn: function (aBlock){
+var self=this;
+var collection=nil;
+collection=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []);
+smalltalk.send(self, "_do_", [(function(each){return ((($receiver = smalltalk.send(aBlock, "_value_", [each])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return smalltalk.send(collection, "_add_", [each]);})() : nil) : smalltalk.send($receiver, "_ifTrue_", [(function(){return smalltalk.send(collection, "_add_", [each]);})]));})]);
+return collection;
+return self;},
+args: ["aBlock"],
+source: unescape('select%3A%20aBlock%0A%09%7C%20collection%20%7C%0A%09collection%20%3A%3D%20self%20class%20new.%20%0A%09self%20do%3A%20%5B%3Aeach%20%7C%0A%09%09%28aBlock%20value%3A%20each%29%20ifTrue%3A%20%5B%0A%09%09%09collection%20add%3A%20each%5D%5D.%0A%09%5Ecollection'),
+messageSends: ["new", "class", "do:", "ifTrue:", "value:", "add:"],
+referencedClasses: []
+}),
+smalltalk.Set);
+
 
 
 smalltalk.addClass('HashedCollection', smalltalk.Collection, [], 'Kernel-Collections');

+ 9 - 0
st/Kernel-Collections.st

@@ -1252,6 +1252,15 @@ detect: aBlock ifNone: anotherBlock
 
 do: aBlock
 	elements do: aBlock
+!
+
+select: aBlock
+	| collection |
+	collection := self class new. 
+	self do: [:each |
+		(aBlock value: each) ifTrue: [
+			collection add: each]].
+	^collection
 ! !
 
 !Set methodsFor: 'initialization'!