'From Squeak3.7beta of ''1 April 2004'' [latest update: #5969] on 13 July 2004 at 11:25:56 am'! "Change Set: BeforeAfterIfAbsentFixV2 Date: 13 July 2004 Author: andrew@beta4.com Made SequenceableCollection>>before:ifAbsent: and SequenceableCollection>>after:ifAbsent: work as advertised: - previously, these methods raised an Error when the element passed in is the first or last one, respectively, when they should have executed the ifAbsent block, as the comments in the method state V2: md: added trivial test"! !SequenceableCollection methodsFor: 'accessing' stamp: 'ac 7/5/2004 22:35'! after: target ifAbsent: exceptionBlock "Answer the element after target. Answer the result of evaluation the exceptionBlock if target is not in the receiver, or if there are no elements after it." | index | index _ self indexOf: target. ^ (index == 0 or: [index = self size]) ifTrue: [exceptionBlock value] ifFalse: [self at: index + 1]! ! !SequenceableCollection methodsFor: 'accessing' stamp: 'ac 7/5/2004 22:36'! before: target ifAbsent: exceptionBlock "Answer the receiver's element immediately before target. Answer the result of evaluating the exceptionBlock if target is not an element of the receiver, or if there are no elements before it." | index | index _ self indexOf: target. ^ (index == 0 or: [index == 1]) ifTrue: [exceptionBlock value] ifFalse: [self at: index - 1]! ! !SequenceableCollectionTest methodsFor: 'testing - testing' stamp: 'md 7/13/2004 11:21'! testAfterIfAbsent | col | col := #(2 3 4). self assert: ((col after: 4 ifAbsent: ['block']) = 'block'). self assert: ((col after: 5 ifAbsent: ['block']) = 'block'). self assert: ((col after: 2 ifAbsent: ['block']) = 3).! ! !SequenceableCollectionTest methodsFor: 'testing - testing' stamp: 'md 7/13/2004 11:21'! testBeforeIfAbsent | col | col := #(2 3 4). self assert: ((col before: 2 ifAbsent: ['block']) = 'block'). self assert: ((col before: 5 ifAbsent: ['block']) = 'block'). self assert: ((col before: 3 ifAbsent: ['block']) = 2).! !