|
Class: RecursiveSeriesStream
Object
|
+--Stream
|
+--PeekableStream
|
+--IteratorStream
|
+--RecursiveSeriesStream
- Package:
- stx:libbasic2
- Category:
- Streams
- Version:
- rev:
1.4
date: 2019/11/19 14:23:27
- user: cg
- file: RecursiveSeriesStream.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
documentation to be added.
class:
<a short class summary here, describing what instances represent>
responsibilities:
<describing what my main role is>
collaborators:
<describing with whom and how I talk to>
API:
<public api and main messages>
example:
<a one-line examples on how to use - can also be in a separate example method>
implementation:
<implementation points>
[instance variables:]
[class variables:]
example|collatz|
collatz := [:n | RecursiveSeriesStream on:[:n | n even ifTrue:[n/2] ifFalse:[n*3+1]] startValue:n].
(collatz[20]) next:20.
(collatz[24]) next:20.
(collatz[25]) next:30.
example2|max bits collatz newNums|
newNums := OrderedCollection new.
bits := SortedCollection new.
max := 2.
collatz := RecursiveSeriesStream on:[:n | n even ifTrue:[n/2] ifFalse:[(n*3+1)/2]] startValue:1.
1 to:100000 do:[:n0 |
newNums removeAll.
collatz startValue:n0.
[
|n|
n := collatz next.
newNums add:n.
n <= max
] whileFalse.
bits addAll:newNums.
[bits notEmpty and:[bits first <= (max+1)]] whileTrue:[max := max max:(bits first). bits removeFirst].
].
self halt.
instance creation
-
on: aBlock startValue: startValue
-
accessing
-
atEnd
-
-
endValue: something
-
define a stop value
-
iterator: aOneArgBlock startValue: startValue
-
-
startValue: startValue
-
reading
-
next
-
return the next element from the stream by evaluating the nextBlock
|