added #at:ifPresent:
authorClaus Gittinger <cg@exept.de>
Thu, 07 Oct 1999 13:37:14 +0200
changeset 4871 211a7f44946d
parent 4870 3f6a8c368925
child 4872 97d6aa9db3e9
added #at:ifPresent:
Dictionary.st
--- a/Dictionary.st	Thu Oct 07 13:35:01 1999 +0200
+++ b/Dictionary.st	Thu Oct 07 13:37:14 1999 +0200
@@ -248,6 +248,18 @@
     "Modified: / 26.2.1998 / 19:10:09 / stefan"
 !
 
+at:aKey ifPresent:aBlock
+    "if the receiver contains an element stored under aKey,
+     retrieve it and evaluate aBlock passing the element as argument,
+     return the blocks value.
+     If not, do nothing and return nil."
+
+    |v|
+
+    v := self at:aKey ifAbsent:[^ nil].
+    ^ aBlock value:v.
+!
+
 at:aKey put:anObject
     "add the argument anObject under key, aKey to the receiver.
      Return anObject (sigh).
@@ -1431,5 +1443,5 @@
 !Dictionary class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.60 1998-11-09 21:34:15 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Dictionary.st,v 1.61 1999-10-07 11:37:14 cg Exp $'
 ! !