added: #to:collect:
authorClaus Gittinger <cg@exept.de>
Fri, 27 Nov 2009 20:48:19 +0100
changeset 12565 11eea3f4ef0b
parent 12564 d0688da84154
child 12566 4e8084624f5d
added: #to:collect:
Integer.st
--- a/Integer.st	Sat Nov 21 22:36:01 2009 +0100
+++ b/Integer.st	Fri Nov 27 20:48:19 2009 +0100
@@ -1139,7 +1139,6 @@
     ^ self == Integer
 ! !
 
-
 !Integer methodsFor:'Compatibility-Dolphin'!
 
 & aNumber
@@ -2505,6 +2504,28 @@
 ! !
 
 
+!Integer methodsFor:'iteration'!
+
+to:stop collect:aBlock
+    "syntactic sugar; 
+     same as (self to:stop) collect:aBlock"
+
+    |n a|
+
+    n := stop - self + 1.
+    a := Array new:n.
+    self to:stop do:[:i |
+        a at:(i-self+1) put:(aBlock value:i).
+    ].
+    ^ a.
+
+    "
+     1 to:10 collect:[:i | i squared]
+     10 to:20 collect:[:i | i squared]  
+     (10 to:20) collect:[:i | i squared]
+    "
+! !
+
 !Integer methodsFor:'misc math'!
 
 acker:n
@@ -3844,7 +3865,6 @@
     "Modified: 15.10.1997 / 18:43:49 / cg"
 ! !
 
-
 !Integer methodsFor:'special access'!
 
 exponent
@@ -4471,11 +4491,11 @@
 !Integer class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.235 2009-11-05 16:25:26 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.236 2009-11-27 19:48:19 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.235 2009-11-05 16:25:26 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Integer.st,v 1.236 2009-11-27 19:48:19 cg Exp $'
 ! !
 
 Integer initialize!