OrderedDictionary.st
changeset 15759 3d3ab3a446e5
parent 15662 e87729351c27
child 15801 9a2b30dc6345
--- a/OrderedDictionary.st	Sat Sep 14 12:35:45 2013 +0200
+++ b/OrderedDictionary.st	Sun Sep 15 12:43:49 2013 +0200
@@ -171,7 +171,7 @@
 
 at: key put: anObject 
     "Set the value at key to be anObject. 
-     If key is not found, create a new entry for key and set is value to anObject. 
+     If key is not found, create a new entry for key and set its value to anObject. 
      If key is already present, the order remains unchanged.
      Return anObject."
 
@@ -334,8 +334,7 @@
     | key |
 
     key := anAssociation key.
-    (super includesKey: key)
-            ifFalse: [order add: key].
+    (super includesKey: key) ifFalse: [order add: key].
     ^ super add: anAssociation
 !
 
@@ -544,6 +543,21 @@
     ^ order collect:[:key | (aBlock value: (self at:key))].
 !
 
+detect: aBlock ifNone:exceptionBlock
+    "evaluate the argument, aBlock for each element in the receiver until
+     the block returns true; in this case return the element which caused
+     the true evaluation.
+     If none of the evaluations returns true, return the result of the
+     evaluation of the exceptionBlock"
+
+    order do:[:key | 
+        |el|
+
+        (aBlock value: (el := self at:key)) ifTrue:[^ el]
+    ].
+    ^ exceptionBlock value
+!
+
 do: aBlock 
     "Evaluate aBlock for each of the dictionary's values."
 
@@ -609,6 +623,21 @@
     ].
 !
 
+keysAndValuesDetect: aBlock ifNone:exceptionBlock
+    "evaluate the argument, aBlock for each element in the receiver until
+     the block returns true; in this case return the element which caused
+     the true evaluation.
+     If none of the evaluations returns true, return the result of the
+     evaluation of the exceptionBlock"
+
+    order do:[:key | 
+        |el|
+
+        (aBlock value:key value: (el := self at:key)) ifTrue:[^ el]
+    ].
+    ^ exceptionBlock value
+!
+
 keysAndValuesDo:aBlock
     "perform the block for all keys and values in the collection.
      Enumerate them in the order by which they were added.
@@ -987,10 +1016,10 @@
 !OrderedDictionary class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/OrderedDictionary.st,v 1.43 2013-08-21 11:16:23 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/OrderedDictionary.st,v 1.44 2013-09-15 10:43:49 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/OrderedDictionary.st,v 1.43 2013-08-21 11:16:23 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/OrderedDictionary.st,v 1.44 2013-09-15 10:43:49 cg Exp $'
 ! !