Issue 3533 in pharo: add Dictionary>>at:ifAbsentPutValue:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue 3533 in pharo: add Dictionary>>at:ifAbsentPutValue:

pharo
Status: Accepted
Owner: stephane.ducasse
Labels: Milestone-1.3

New issue 3533 by stephane.ducasse: add Dictionary>>at:ifAbsentPutValue:
http://code.google.com/p/pharo/issues/detail?id=3533

Igor suggests to add this method in dictionary to avoid to use block  
closure when not necessary.

Here the block has to be passed and executed. When you know the value you  
want to put this is extra work.

at: key ifAbsentPut: aBlock
        "Return the value at the given key.
        If key is not included in the receiver store the result
        of evaluating aBlock as new value."

        ^ self at: key ifAbsent: [self at: key put: aBlock value]




Reply | Threaded
Open this post in threaded view
|

Re: Issue 3533 in pharo: add Dictionary>>at:ifAbsentPutValue:

pharo

Comment #1 on issue 3533 by stephane.ducasse: add  
Dictionary>>at:ifAbsentPutValue:
http://code.google.com/p/pharo/issues/detail?id=3533

at: key ifAbsentPutValue: anObject
        "Return the value at the given key.
        If key is not included in the receiver store the new value."

        ^ self at: key ifAbsent: [self at: key put: anObject ]