stream 0.5.2 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3374a923bc2d44c39ea1c1957d5982b26f55a22ac958cfa119be87a978e17676
4
- data.tar.gz: 88b9b768b08a6edf3a689f76f50627784825b15ac1ed07d6b3172bb34ce69fa3
3
+ metadata.gz: 01b456afc318137cc9291dd8f7ec664dcc6370225c1fb8cf0a223794d1a18cb7
4
+ data.tar.gz: 19824c0406a4e7b253aa682db312f89fea8a1d0c9bd3a3513d2951ffdc3126b2
5
5
  SHA512:
6
- metadata.gz: fd0f115fefc0969ccde444c8200d9f279b8d9736af6c91884d89e5fa9dd4a46dccb6b570da4467b7dfaa35e038644b09dbf25348289a66cf0ea919c4c21c732b
7
- data.tar.gz: 56d49b892e3355026bb05bd98535471ebfe9e8564f9f1885e43938deda8b7f3e33551fcd15f1b492821944de5707ef296dff3f134812b1f8e904ce0ef8b4f037
6
+ metadata.gz: c3fdb6526fabfd8ff52d8ea5b195f83a5644515f99444ab589d389ffb08365dea6de40e69e84bd8c9c93155cabcee3fe0a0e2ef0dd1a96403a7dc2035bf80be2
7
+ data.tar.gz: 95c2179dca08a24eb24f7aa811be95b4bd1c17ea57e41d218ada55783933cdac30eb958ca61a42294bc719097d98327fe846248bf7f88b47272776fbfcddff07
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem "codeclimate-test-reporter", group: :test, require: nil
data/Gemfile.lock CHANGED
@@ -1,32 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stream (0.5.2)
4
+ stream (0.5.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- codeclimate-test-reporter (1.0.9)
10
- simplecov (<= 0.13)
11
- docile (1.1.5)
12
- json (2.1.0)
13
- power_assert (1.1.3)
14
- rake (12.3.2)
15
- rdoc (6.1.1)
16
- simplecov (0.13.0)
17
- docile (~> 1.1.0)
18
- json (>= 1.8, < 3)
19
- simplecov-html (~> 0.10.0)
20
- simplecov-html (0.10.2)
21
- 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)
22
17
  power_assert
23
- yard (0.9.16)
18
+ webrick (1.7.0)
19
+ yard (0.9.28)
20
+ webrick (~> 1.7.0)
24
21
 
25
22
  PLATFORMS
26
23
  ruby
24
+ x86_64-linux
27
25
 
28
26
  DEPENDENCIES
29
- codeclimate-test-reporter
30
27
  rake
31
28
  rdoc
32
29
  stream!
@@ -34,4 +31,4 @@ DEPENDENCIES
34
31
  yard
35
32
 
36
33
  BUNDLED WITH
37
- 2.0.1
34
+ 2.3.8
data/LICENSE ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/README.rdoc CHANGED
@@ -1,11 +1,12 @@
1
- {<img src="https://secure.travis-ci.org/monora/stream.png?branch=master" alt="Build Status" />}[https://travis-ci.org/monora/stream]
1
+ {<img src="https://github.com/monora/stream/actions/workflows/ruby.yml/badge.svg" alt="Build Status" />}[https://github.com/monora/stream/actions/workflows/ruby.yml]
2
2
 
3
3
  = Extended External Iterators (forward and backward)
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 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/Rakefile CHANGED
@@ -21,8 +21,8 @@ task :default => :test
21
21
  # Define a test task.
22
22
 
23
23
  Rake::TestTask.new do |t|
24
- t.libs << "tests"
25
- t.pattern = 'tests/Test*.rb'
24
+ t.libs << 'test'
25
+ t.pattern = 'test/test*.rb'
26
26
  t.verbose = true
27
27
  end
28
28