Dictionary.st
changeset 16808 793e0523328e
parent 16728 0182965b1985
child 16902 869a0975a957
--- a/Dictionary.st	Thu Jul 31 14:29:29 2014 +0200
+++ b/Dictionary.st	Fri Aug 01 14:52:05 2014 +0200
@@ -230,6 +230,7 @@
     ^ self = aDictionary
 ! !
 
+
 !Dictionary methodsFor:'accessing'!
 
 associationAt:aKey
@@ -1943,6 +1944,24 @@
 
 !Dictionary methodsFor:'searching'!
 
+findFirst:aBlock ifNone:exceptionValue
+    "find the index of the first element, for which evaluation of the argument, aBlock returns true; 
+     return its index or the value from exceptionValue if none detected.
+     This is much like #detect:ifNone:, however, here an INDEX is returned,
+     while #detect:ifNone: returns the element.
+
+     Here we return the first key for which aBlock matches the value.
+     Note that there is no order in a Dictionary, so any element is first."
+
+    self keysAndValuesDo:[:eachKey :eachValue| (aBlock value:eachValue) ifTrue:[^ eachKey]].
+    ^ exceptionValue value.
+
+    "
+        (Dictionary withKeys:#('a' 'b' 'c') andValues:#('bla' 'hello' 'hallo'))
+            findFirst:[:v| v first = $h].
+    "
+!
+
 findFirstKey:aBlock
     "find and return the first key, for which evaluation of the argument, aBlock
      returns true; return nil if none is detected."
@@ -2138,10 +2157,10 @@
 !Dictionary class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.120 2014-07-09 16:21:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.121 2014-08-01 12:52:05 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.120 2014-07-09 16:21:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.121 2014-08-01 12:52:05 stefan Exp $'
 ! !