Mantis - Squeak
Viewing Issue Advanced Details
6364 Collections minor always 03-21-07 18:23 04-18-10 21:59
bfowlow  
nicolas cellier  
normal  
closed 3.8  
fixed  
none    
none trunk  
0006364: Collections ifEmpty: returns nil on non-empty
Collection ifEmpty: [ foo ]
returns nil if the collection is not empty,
owing to the placement of the return in

        ifEmpty: aBlock
                "Evaluate the block if I'm empty"
                ^ self isEmpty ifTrue: aBlock


It would be (I think) more useful to say
        ifEmpty: aBlock
                self isEmpty ifTrue: [ ^ aBlock value ]

returning the original collection if non-empty,
... since this allows expressions such as

        foo := (collection allAfterLast:'@') ifEmpty: [collection].

Notes
(0013432)
nicolas cellier   
12-12-09 18:28   
resolved in trunk by Levente (Collections-ul.186)