--- a/SequenceableCollection.st Tue Aug 25 07:04:02 2015 +0200
+++ b/SequenceableCollection.st Sun Aug 30 06:37:05 2015 +0200
@@ -751,6 +751,7 @@
^ self replaceFrom:start to:stop with:anArray startingAt:repStart
! !
+
!SequenceableCollection methodsFor:'accessing'!
after:anObject
@@ -7638,6 +7639,7 @@
"Created: 14.2.1997 / 16:13:03 / cg"
! !
+
!SequenceableCollection methodsFor:'searching'!
detect:aBlock startingAt:startIndex
@@ -7678,6 +7680,51 @@
"Created: / 21.10.1998 / 18:46:01 / cg"
!
+detectLast:aBlock
+ "find the last element, for which evaluation of the argument, aBlock returns true.
+ If none does so, report an error"
+
+ ^ self detectLast:aBlock startingAt:self size ifNone:[self errorNotFound]
+
+ "
+ #(11 12 13 14) detectLast:[:n | n odd]
+ #(12 14 16 18) detectLast:[:n | n odd] ifNone:'sorry'
+ "
+!
+
+detectLast:aBlock startingAt:startIndex
+ "find the last element, for which evaluation of the argument, aBlock returns true.
+ Start the backward search at startIndex.
+ If none does so, report an error"
+
+ ^ self detectLast:aBlock startingAt:startIndex ifNone:[self errorNotFound]
+
+ "
+ #(11 12 13 14) detectLast:[:n | n odd] startingAt:3
+ #(12 14 16 18) detectLast:[:n | n odd] startingAt:3
+ "
+
+ "Created: / 21.10.1998 / 18:47:28 / cg"
+!
+
+detectLast:aBlock startingAt:startIndex ifNone:exceptionBlock
+ "find the last element, for which evaluation of the argument, aBlock returns true.
+ Start the backward search at startIndex.
+ If none does so, return the evaluation of exceptionBlock"
+
+ self from:startIndex to:1 by:-1 do:[:el |
+ (aBlock value:el) ifTrue:[
+ ^ el
+ ].
+ ].
+ ^ exceptionBlock value
+
+ "
+ #(11 12 13 14) detectLast:[:n | n odd] startingAt:3 ifNone:['sorry']
+ #(12 14 16 18) detectLast:[:n | n odd] startingAt:3 ifNone:['sorry']
+ "
+!
+
findFirst:aBlock ifNone:exceptionalValue
"find the index of the first element, for which evaluation of the argument, aBlock returns true.
Return its index or the value from exceptionalValue if none detected.