#REFACTORING by cg
authorClaus Gittinger <cg@exept.de>
Fri, 06 May 2016 18:22:39 +0200
changeset 19734 f08c3560f055
parent 19733 34ff21b5c668
child 19735 bb4d212a1a02
#REFACTORING by cg class: Collection moved: #keysAndValuesDetect:ifNone:
Collection.st
--- a/Collection.st	Fri May 06 12:54:42 2016 +0200
+++ b/Collection.st	Fri May 06 18:22:39 2016 +0200
@@ -3212,6 +3212,29 @@
     "Modified: 20.4.1996 / 11:33:50 / cg"
 !
 
+keysAndValuesDetect:aBlock ifNone:exceptionalValue
+    "for each key-value pair in the receiver, evaluate the argument, aBlock
+     and return the value for which aBlock returns true the very first time.
+     If none of the evaluations returns true, return the result of the
+     evaluation of the exceptionBlock"
+     
+    self keysAndValuesDo:[:key :value |
+        (aBlock value:key value:value) ifTrue:[^ value].
+    ].
+    ^ exceptionalValue value
+
+    "
+     |ages|
+
+     ages := Dictionary new.
+     ages at:'cg' put:37.
+     ages at:'ca' put:33.
+     ages at:'sv' put:36.
+     ages at:'tk' put:28.
+     ages keysAndValuesDetect:[:name :age | age = 33].
+    "
+!
+
 keysAndValuesDo:aTwoArgBlock
     "evaluate the argument, aBlock for every element in the collection,
      passing both index and element as arguments.