--- a/Collection.st Mon Sep 11 16:33:31 2017 +0200
+++ b/Collection.st Wed Sep 13 11:38:06 2017 +0200
@@ -2718,22 +2718,23 @@
!
detect:aOneArgBlock ifNone:exceptionValue
- "evaluate the argument, aBlock for each element in the receiver until
- the block returns true; in this case return the element which caused
- the true evaluation.
+ "evaluate the argument aOneArgBlock for each element in the receiver until
+ the block returns true; in this case return the element that caused the
+ true evaluation.
If none of the evaluations returns true, return the value from exceptionValue"
- self do:[:each |
+ self do:[:each |
(aOneArgBlock value:each) ifTrue:[^ each].
].
^ exceptionValue value
"
- #(1 2 3 4) detect:[:n | n odd] ifNone:['sorry']
- #(2 4 6 8) detect:[:n | n odd] ifNone:['sorry']
+ #(1 2 3 4) detect:[:n | n odd] ifNone:['sorry']
+ #(2 4 6 8) detect:[:n | n odd] ifNone:['sorry']
"
"Modified: / 13-09-2006 / 11:17:42 / cg"
+ "Modified (comment): / 13-09-2017 / 11:34:47 / mawalch"
!
detect:checkBlock thenCompute:evalBlock
@@ -2754,26 +2755,28 @@
!
detect:checkBlock thenCompute:evalBlock ifNone:exceptionValue
- "evaluate the argument, aBlock for each element in the receiver until
- checkBck returns true; in this case return the value from evalBlock
- applied to the element which caused the true evaluation.
+ "evaluate the argument checkBlock for each element in the receiver until
+ it returns true; in this case return the value from evalBlock applied to
+ the element that caused the true evaluation.
If none of the evaluations returns true, return the value from exceptionValue."
|foundElement|
-
+
foundElement := self detect:checkBlock ifNone:[^ exceptionValue value].
^ evalBlock value:foundElement.
"
- #((1 'one') (2 'two') (3 'three') (4 'four'))
- detect:[:pair | pair first odd] thenCompute:[:pair | pair second]
- ifNone:[ nil ].
- "
- "
- #( (2 'two') (4 'four'))
+ #((1 'one') (2 'two') (3 'three') (4 'four'))
detect:[:pair | pair first odd] thenCompute:[:pair | pair second]
ifNone:[ nil ].
"
+ "
+ #( (2 'two') (4 'four'))
+ detect:[:pair | pair first odd] thenCompute:[:pair | pair second]
+ ifNone:[ nil ].
+ "
+
+ "Modified (comment): / 13-09-2017 / 11:33:51 / mawalch"
!
detectLast:aBlock