#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Mon, 21 Jan 2019 13:15:04 +0100
changeset 23620 96d2b2517324
parent 23619 90c9530305b7
child 23621 f19f56a9e038
#FEATURE by cg class: Collection added: #keysAndValuesSelect:
Collection.st
--- a/Collection.st	Mon Jan 21 10:31:25 2019 +0100
+++ b/Collection.st	Mon Jan 21 13:15:04 2019 +0100
@@ -3640,6 +3640,28 @@
     "Created: 9.5.1996 / 00:58:24 / cg"
 !
 
+keysAndValuesSelect:selectBlockWith2Args
+    "first call the selectBlockWith2Args, passsing it each key and element,
+     collect the elements for which the block returns true in an OrderedCollection."
+    
+    |collected|
+
+    collected := OrderedCollection new.
+    self keysAndValuesDo:[:eachKey :eachValue |
+        (selectBlockWith2Args value:eachKey value:eachValue) ifTrue:[
+            collected add:eachValue
+        ].
+    ].
+    ^ collected
+
+    "
+     #(10 20 30 40) 
+        keysAndValuesSelect:[:idx :val | idx odd] 
+    "
+
+    "Created: / 21-01-2019 / 13:14:30 / Claus Gittinger"
+!
+
 keysAndValuesSelect:selectBlockWith2Args thenCollect:collectBlockWith2Args
     "first call the selectBlockWith2Args, passsing it each key and element,
      if that returns true, call the collectBlockWith2Args, also with key and element,