Collection.st
changeset 24510 e309e5fdf190
parent 24397 f8bd0c337564
child 24603 154e9e58b45e
--- a/Collection.st	Thu Aug 08 16:17:09 2019 +0200
+++ b/Collection.st	Thu Aug 08 19:37:28 2019 +0200
@@ -2853,6 +2853,9 @@
     "
      #((1 one) (2 two) (3 three) (4 four)) collectColumn:1
      #((1 one) (2 two) (3 three) (4 four)) collectColumn:2
+    similar (but more general) to:
+     #((1 one) (2 two) (3 three) (4 four)) collect:#first
+     #((1 one) (2 two) (3 three) (4 four)) collect:#second
     "
 
     "Created: / 22-09-2018 / 11:18:37 / Claus Gittinger"
@@ -3314,11 +3317,44 @@
     "Modified (comment): / 05-08-2018 / 11:26:46 / Claus Gittinger"
 !
 
+doWhileFalse:aBlock
+    "evaluate the argument, aBlock for each element,
+     until it evaluates to true.
+     Answer false, if all the elements have been processed,
+     true otherwise.
+     Notice: to get the element, use #detect:ifNone:
+             to get its index, use #findFirst:ifNone:"
+
+    self do:[:el |
+        (aBlock value:el) ifTrue:[
+            ^ true.
+        ]
+    ].
+    ^ false
+
+    "Example:
+     search for the first element which is >= 99; return it.
+     remaining elements are not processed:
+
+     |lastElement|
+
+     #(1 2 3 4 999 5 6 7 8 9) 
+        doWhileFalse:[:element|
+            Transcript showCR:element.
+            lastElement := element.
+            element >= 99
+        ].
+     lastElement
+    "
+!
+
 doWhileTrue:aBlock
     "evaluate the argument, aBlock for each element,
-     until the block evaluates to false.
+     until it evaluates to false.
      Answer true, if all the elements have been processed,
-     false otherwise."
+     false otherwise.
+     Notice: to get the element, use #detect:ifNone:
+             to get its index, use #findFirst:ifNone:"
 
     self do:[:el |
         (aBlock value:el) ifFalse:[