added #at:ifPresent:
authorClaus Gittinger <cg@exept.de>
Thu, 07 Oct 1999 13:35:01 +0200
changeset 4870 3f6a8c368925
parent 4869 45bae3b31eef
child 4871 211a7f44946d
added #at:ifPresent:
Smalltalk.st
--- a/Smalltalk.st	Thu Oct 07 12:57:21 1999 +0200
+++ b/Smalltalk.st	Thu Oct 07 13:35:01 1999 +0200
@@ -461,6 +461,10 @@
 
 !
 
+isMorphic
+    ^ false
+!
+
 registerExternalObject: anObject
     "Register the given object in the external objects array and return its index.
      If it is already there, just return its index.
@@ -572,6 +576,23 @@
     "
 !
 
+at:aKey ifPresent:aBlock
+    "try to retrieve the value stored at aKey.
+     If there is nothing stored under this key, do nothing.
+     Otherwise, evaluate aBlock, passing the retrieved value as argument."
+
+    (self includesKey:aKey) ifTrue:[
+        ^ aBlock value:(self at:aKey)
+    ].
+    ^ nil
+
+    "
+     Smalltalk at:#fooBar ifPresent:[:what | Transcript showCR:what].
+     Smalltalk at:#Object ifPresent:[:what | Transcript showCR:what].
+    "
+
+!
+
 at:aKey put:aValue
     "store the argument aValue under aKey, a symbol.
      Return aValue (sigh)."
@@ -4845,5 +4866,5 @@
 !Smalltalk class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.363 1999-10-04 18:45:59 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Smalltalk.st,v 1.364 1999-10-07 11:35:01 cg Exp $'
 ! !