Iterator.st
changeset 878 0bef2108e3a9
parent 586 8ec7b5171fb9
child 885 c31412b26306
--- a/Iterator.st	Mon Jan 31 14:59:03 2000 +0100
+++ b/Iterator.st	Sat Feb 05 15:29:07 2000 +0100
@@ -99,45 +99,79 @@
 
 examples
 "
- an iterator, simulating a collection of 100 random values:
-									[exBegin]
+ an iterator, simulating the collection of all classes in the system:
+                                                                        [exBegin]
+     |i b|
+
+     b := [:whatToDo |
+               Smalltalk allClassesDo:[:cls | 
+                  whatToDo value:cls
+               ] 
+          ].
+
+     i := Iterator on:b.
+     i do:[:cls |
+        Transcript showCR:cls name
+     ].
+                                                                        [exEnd]
+ much like above, one that simulates the collection of all methodNames starting with 'a':
+                                                                        [exBegin]
      |i b|
 
      b := [:whatToDo |
-	       |rnd|
+               Smalltalk allClassesDo:[:cls |
+                  cls methodDictionary keysAndValuesDo:[:nm :mthd |
+                    (nm startsWith:$a) ifTrue:[
+                       whatToDo value:nm
+                     ]
+                  ]
+               ] 
+          ].
 
-	       rnd := Random new.
-	       1 to:100 do:[:i | 
-		  whatToDo value:(rnd next)
-	       ] 
-	  ].
+     i := Iterator on:b.
+     i do:[:nm |
+        Transcript showCR:nm
+     ].
+                                                                        [exEnd]
+ an iterator, simulating a collection of 100 random values:
+                                                                        [exBegin]
+     |i b|
+
+     b := [:whatToDo |
+               |rnd|
+
+               rnd := Random new.
+               1 to:100 do:[:i | 
+                  whatToDo value:(rnd next)
+               ] 
+          ].
 
      i := Iterator on:b.
      i do:[:j |
-	j printNL
+        j printNL
      ].
-									[exEnd]
+                                                                        [exEnd]
  an iterator, simulating a collection of the lines
  in a file:
-									[exBegin]
+                                                                        [exBegin]
      |i b|
 
      b := [:whatToDo |
-	       |s line|
+               |s line|
 
-	       s := 'smalltalk.rc' asFilename readStream.
-	       [s atEnd] whileFalse:[
-		  line := s nextLine.
-		  whatToDo value:line.
-	       ].
-	       s close
-	  ].
+               s := 'smalltalk.rc' asFilename readStream.
+               [s atEnd] whileFalse:[
+                  line := s nextLine.
+                  whatToDo value:line.
+               ].
+               s close
+          ].
 
      i := Iterator on:b.
      i do:[:j |
-	j printNL
+        j printNL
      ].
-									[exEnd]
+                                                                        [exEnd]
 "
 ! !
 
@@ -323,5 +357,5 @@
 !Iterator class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/Iterator.st,v 1.6 1997-11-02 17:35:27 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/Iterator.st,v 1.7 2000-02-05 14:29:07 cg Exp $'
 ! !