The Trunk: Collections-cmm.325.mcz

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

The Trunk: Collections-cmm.325.mcz

commits-2
Chris Muller uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-cmm.325.mcz

==================== Summary ====================

Name: Collections-cmm.325
Author: cmm
Time: 4 March 2010, 9:46:10.488 pm
UUID: 9e847ff1-32bd-4500-bc4a-8bf745d38e15
Ancestors: Collections-nice.324

Added Dictionary>>#at:ifPresent:ifAbsent:.  

When Dictionary already offers #at:ifPresent: and #at:ifAbsent: api, it is natural to expect, and better to write:

        d
                at: key
                ifPresent: [ : found | .... ]
                ifAbsent: [ ... ]

than:

        (d
                at: key
                ifPresent: [ : found | ... ])
                ifNil:
                        [ "absent"
                        ... ].
               
The new 5-line method relies on the legacy #at:ifPresent:.

=============== Diff against Collections-nice.324 ===============

Item was added:
+ ----- Method: Dictionary>>at:ifPresent:ifAbsent: (in category 'accessing') -----
+ at: key ifPresent: oneArgBlock ifAbsent: absentBlock
+ "Lookup the given key in the receiver. If it is present, answer the value of evaluating the oneArgBlock with the value associated with the key, otherwise answer the value of absentBlock."
+ ^(self
+ at: key
+ ifPresent: oneArgBlock) ifNil: absentBlock!