'From Squeak3.7alpha of ''11 September 2003'' [latest update: #5657] on 30 January 2004 at 3:43:15 pm'! "Change Set: ifEmptyParam-md Date: 30 January 2004 Author: Marcus Denker Julian Fitzell posted a changeset to add ifEmpty/ifNotEmpty methods to Collection. This is now part of 3.7a. From his changeset preamble: -- There was some discussion and it was agreed that they should all take 0-arg blocks in all their forms and we could add #ifEmptyDo:, etc. at a later point if desired. -- Now there's a nice way of having ifEmpty: take both a 0-arg block (like ifNotNil:) and a 1-arg block (like ifNotNilDo:) by using valueWithPossibleArgs: to double-dispatch on the number of arguments in the block. ifNotEmpty: aBlock ^self isEmpty ifFalse: [aBlock valueWithPossibleArgs: {self}]. enabeling both #(1) ifNotEmpty: [:i | i first] #(1) ifNotEmpty: ['hello'] This changeset changes ifNotEmpty:/ifNotEmpty:ifEmpty and ifEmpty:ifNotEmpty to use valueWithPossibleArgs. I think it would be good to have the ifNotNil inlining and the methods to take both 0-Arg and 1-Arg blocks, too. I will look into this later. "! !Collection methodsFor: 'testing' stamp: 'md 1/30/2004 15:11'! ifEmpty: emptyBlock ifNotEmpty: notEmptyBlock "Evaluate emptyBlock if I'm empty, notEmptyBlock otherwise" ^ self isEmpty ifTrue: emptyBlock ifFalse: [notEmptyBlock valueWithPossibleArgs: {self}]! ! !Collection methodsFor: 'testing' stamp: 'md 1/30/2004 15:08'! ifNotEmpty: aBlock "Evaluate the block unless I'm empty" ^self isEmpty ifFalse: [aBlock valueWithPossibleArgs: {self}]. ! ! !Collection methodsFor: 'testing' stamp: 'md 1/30/2004 15:11'! ifNotEmpty: notEmptyBlock ifEmpty: emptyBlock "Evaluate emptyBlock if I'm empty, notEmptyBlock otherwise" ^ self isEmpty ifFalse: [notEmptyBlock valueWithPossibleArgs: {self}] ifTrue: emptyBlock! !