stream 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +12 -8
  3. data/README.rdoc +67 -59
  4. data/lib/stream.rb +1 -1
  5. metadata +2 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55354ecc39933e7f4be1b3b1eaa9bcfec109b00346f739e2f6c675a333ed17e9
4
- data.tar.gz: aab007abb0bf1bf998be99a9806d3e3d9a8f305a422ce01ac83ea586b42a778a
3
+ metadata.gz: 01b456afc318137cc9291dd8f7ec664dcc6370225c1fb8cf0a223794d1a18cb7
4
+ data.tar.gz: 19824c0406a4e7b253aa682db312f89fea8a1d0c9bd3a3513d2951ffdc3126b2
5
5
  SHA512:
6
- metadata.gz: 416c8fe937cc016744b8325bd3f15a6210a51fe17900de8e1db8b405ef5793cd2344ff3f0e9b0a3e336bf71c1497b9f84137238f4f92431fa861056f6a34646c
7
- data.tar.gz: c07f8c66b7ca2d3a3e7c355b9b7bdbb6bd3151c9871159b0c92376773a732b9fdbabc2e1727f6b4c822b4412aa67a17f0601afd969f50ecd1a9751618e4c72e3
6
+ metadata.gz: c3fdb6526fabfd8ff52d8ea5b195f83a5644515f99444ab589d389ffb08365dea6de40e69e84bd8c9c93155cabcee3fe0a0e2ef0dd1a96403a7dc2035bf80be2
7
+ data.tar.gz: 95c2179dca08a24eb24f7aa811be95b4bd1c17ea57e41d218ada55783933cdac30eb958ca61a42294bc719097d98327fe846248bf7f88b47272776fbfcddff07
data/Gemfile.lock CHANGED
@@ -1,19 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stream (0.5.4)
5
- generator
4
+ stream (0.5.5)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
9
8
  specs:
10
- generator (0.0.1)
11
- power_assert (1.1.3)
12
- rake (12.3.2)
13
- rdoc (6.1.1)
14
- test-unit (3.2.9)
9
+ power_assert (2.0.1)
10
+ psych (4.0.4)
11
+ stringio
12
+ rake (13.0.6)
13
+ rdoc (6.4.0)
14
+ psych (>= 4.0.0)
15
+ stringio (3.0.2)
16
+ test-unit (3.5.3)
15
17
  power_assert
16
- yard (0.9.16)
18
+ webrick (1.7.0)
19
+ yard (0.9.28)
20
+ webrick (~> 1.7.0)
17
21
 
18
22
  PLATFORMS
19
23
  ruby
data/README.rdoc CHANGED
@@ -4,8 +4,9 @@
4
4
 
5
5
  == Description
6
6
 
7
- Module Stream defines an interface for external iterators. A stream can be
8
- seen as an iterator on a sequence of objects x1,...,xn. The state of the
7
+ Module +Stream+ defines an interface for {external
8
+ iterators}[https://wiki.c2.com/?ExternalIterator]. A stream can be seen
9
+ as an iterator on a sequence of objects +x1,...,xn+. The state of the
9
10
  stream is uniquely determined by the following methods:
10
11
 
11
12
  * at_beginning?
@@ -20,14 +21,15 @@ State changes are done with the following operations:
20
21
  * forward
21
22
  * backward
22
23
 
23
- With the help of the method current_edge the state of a stream s can be
24
+ With the help of the method +current_edge+ the state of a stream +s+ can be
24
25
  exactly defined
25
26
 
26
27
  s.current_edge == [s.current, s.peek]
27
28
 
28
- If s a stream on [x1,...,xn]. Consider the edges [xi,xi+1] i=1,...,n and
29
- [x0,x1] and [xn,xn+1] (x0 and xn+1 are helper elements to define the boundary
30
- conditions). Then if s is non empty, the following conditions must be true:
29
+ If +s+ a stream on [x1,...,xn]. Consider the edges [xi,xi+1] i=1,...,n
30
+ and [x0,x1] and [xn,xn+1] (x0 and xn+1 are helper elements to define
31
+ the boundary conditions). Then if +s+ is non empty, the following
32
+ conditions must be true:
31
33
 
32
34
  s.at_beginning? <=> s.current_edge == [x0,x1]
33
35
  s.at_end? <=> s.current_edge == [xn,xn+1]
@@ -46,16 +48,18 @@ If 1 <= i < n and s.current_edge == [xi, xi+1] , then:
46
48
  The result of peek is the same as of forward without changing state. The result of
47
49
  current is the same as of backward without changing state.
48
50
 
49
- Module Stream includes Enumerable implementing #each in the obvious way.
51
+ Module +Stream+ includes +Enumerable+ implementing +each+ in the obvious way.
50
52
 
51
- Not every stream needs to implement #backward and #at_beginning? thus being
52
- not reversable. If they are reversable peek can easily be implemented using
53
- forward and backward, as is done in module Stream. If a stream is not
54
- reversable all derived streams provided by the stream module (filter,
55
- mapping, concatenation) can be used anyway. Explicit or implicit (via peek or
56
- current) uses of backward would throw a NotImplementedError.
53
+ Not every stream needs to implement +backward+ and +at_beginning?+
54
+ thus being not reversable. If they are reversable peek can easily be
55
+ implemented using +forward+ and +backward+, as is done in module
56
+ +Stream+. If a stream is not reversable all derived streams provided
57
+ by the stream module (filter, mapping, concatenation) can be used
58
+ anyway. Explicit or implicit (via peek or current) uses of backward
59
+ would throw a +NotImplementedError+.
57
60
 
58
- Classes implementing the stream interface must implement the following methods:
61
+ Classes implementing the stream interface must implement the following
62
+ methods:
59
63
 
60
64
  * basic_forward
61
65
  * basic_backward
@@ -63,60 +67,40 @@ Classes implementing the stream interface must implement the following methods:
63
67
  * at_end?
64
68
  * at_beginning?
65
69
 
66
- The methods set_to_end and set_to_begin are by default implemented as:
70
+ The methods +set_to_end+ and +set_to_begin+ are by default implemented
71
+ as:
67
72
 
68
73
  set_to_end : until at_end?; do basic_forward end
69
74
  set_to_begin : until at_beginning?; do basic_backward end
70
75
 
71
- The methods forward and backward are by default implemented as:
76
+ The methods +forward+ and +backward+ are by default implemented as:
72
77
 
73
- forward: raise EndOfStreamException if at_end?; basic_forward.
74
- backward: raise EndOfStreamException if at_beginning?; basic_backward
78
+ forward: raise EndOfStreamException if at_end?; basic_forward.
79
+ backward: raise EndOfStreamException if at_beginning?; basic_backward
75
80
 
76
81
  Thus subclasses must only implement *four* methods. Efficiency sometimes
77
82
  demands better implementations.
78
83
 
79
84
  There are several concrete classes implementing the stream interface:
80
85
 
81
- * Stream::EmptyStream (boring)
82
- * Stream::CollectionStream created by the method Array#create_stream
83
- * Stream::FilteredStream created by the method Stream#filtered
84
- * Stream::ReversedStream created by the method Stream#reverse
85
- * Stream::ConcatenatedStream created by the method Stream#concatenate
86
- * Stream::ImplicitStream using closures for the basic methods to implement
87
-
88
- == Download
89
-
90
- The latest version of stream.rb can be found at
91
-
92
- * http://github.com/monora/stream
86
+ * +Stream::EmptyStream+ (boring)
87
+ * +Stream::CollectionStream+ created by the method +Array#create_stream+
88
+ * +Stream::FilteredStream+ created by the method +Stream#filtered+
89
+ * +Stream::ReversedStream+ created by the method +Stream#reverse+
90
+ * +Stream::ConcatenatedStream+ created by the method +Stream#concatenate+
91
+ * +Stream::ImplicitStream+ using closures for the basic methods to implement
93
92
 
94
93
  == Installation
95
94
 
96
- === Normal Installation
97
-
98
- You can install stream with the following command.
99
-
100
- % ruby install.rb
101
-
102
- from its distribution directory.
103
-
104
- === GEM Installation
105
-
106
- Download the GEM file and install it with ..
107
-
108
- gem -i stream-VERSION.gem
109
-
110
- Use the correct version number for VERSION (e.g. 0.5). You may need
111
- root privileges to install.
95
+ gem install stream
112
96
 
113
- == See also
114
-
115
- * Streams in Smalltalk: http://wiki.cs.uiuc.edu/PatternStories/FunWithStreams
116
- * Simon Strandgaards iterator.rb[http://aeditor.rubyforge.org/iterator/files/iterator_rb.html]
97
+ or download the latest sources from the git repository
98
+ https://github.com/monora/stream.
117
99
 
118
100
  == Examples
119
101
 
102
+ === Iterate over three streams
103
+
120
104
  g = ('a'..'f').create_stream
121
105
  h = (1..10).create_stream
122
106
  i = (10..20).create_stream
@@ -125,6 +109,17 @@ root privileges to install.
125
109
  p [g.forward, h.forward, i.forward]
126
110
  end
127
111
 
112
+ Output:
113
+
114
+ ["a", 1, 10]
115
+ ["b", 2, 11]
116
+ ["c", 3, 12]
117
+ ["d", 4, 13]
118
+ ["e", 5, 14]
119
+ ["f", 6, 15]
120
+
121
+ === Concatenate file streams
122
+
128
123
  def filestream fname
129
124
  Stream::ImplicitStream.new { |s|
130
125
  f = open(fname)
@@ -138,7 +133,7 @@ root privileges to install.
138
133
  puts l
139
134
  end
140
135
 
141
- puts "\nTwo filtered collection streams concatenated and reversed:\n\n"
136
+ === Two filtered collection streams concatenated and reversed
142
137
 
143
138
  def newstream; (1..6).create_stream; end
144
139
  s = newstream.filtered { |x| x % 2 == 0 } + newstream.filtered { |x| x % 2 != 0 }
@@ -150,9 +145,21 @@ root privileges to install.
150
145
  puts "Forward : #{s.forward}"
151
146
  puts "Peek : #{s.peek}"
152
147
  puts "Current : #{s.current}"
153
- puts "set_to_begin : Peek=#{s.set_to_begin;s.peek}"
148
+ puts "set_to_begin : Peek=#{s.set_to_begin;s.peek}"
149
+
150
+ Output:
151
+
152
+ Contents : 5 3 1 6 4 2
153
+ At end? : true
154
+ At beginning? : false
155
+ 2xBackwards : 2 4
156
+ Forward : 4
157
+ Peek : 2
158
+ Current : 4
159
+ set_to_begin : Peek=5
160
+
161
+ === An infinite stream (do not use +set_to_end+!)
154
162
 
155
- # an infinite stream (do not use set_to_end!)
156
163
  def randomStream
157
164
  Stream::ImplicitStream.new { |s|
158
165
  s.set_to_begin_proc = proc {srand 1234}
@@ -160,13 +167,14 @@ root privileges to install.
160
167
  s.forward_proc = proc {rand}
161
168
  }
162
169
  end
163
- s = randomStream.filtered { |x| x >= 0.5 }.collect { |x| sprintf("%5.2f ",x*100) }
164
- puts "5 random numbers: #{(1..5).collect {|x| s.forward}}\n" # =>
170
+ s = randomStream.filtered { |x| x >= 0.5 }.collect { |x| sprintf("%5.2f",x*100) }
171
+ puts "5 random numbers: #{(1..5).collect {|x| s.forward}}\n"
172
+
173
+ Output:
165
174
 
166
- 5 random numbers: 74.05 94.80 87.87 86.07 83.70
175
+ 5 random numbers: ["62.21", "78.54", "78.00", "80.19", "95.81"]
167
176
 
168
- == Other Stuff
177
+ == License
169
178
 
170
179
  Author:: Horst Duchene
171
- License:: Copyright (c) 2001, 2013, 2016, 2020 Horst Duchene
172
- Released under the same license as Ruby
180
+ License:: Copyright (c) 2001, 2013, 2016, 2020, 2022 Horst Duchene (Released under the same license as Ruby (see LICENSE))
data/lib/stream.rb CHANGED
@@ -1,4 +1,4 @@
1
- STREAM_VERSION = '0.5.4'.freeze
1
+ STREAM_VERSION = '0.5.5'.freeze
2
2
 
3
3
  ##
4
4
  # Module Stream defines an interface for an external Iterator which
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Horst Duchene
8
8
  autorequire: stream
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-02 00:00:00.000000000 Z
11
+ date: 2022-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: generator
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement