lazylist 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +2 -0
- data/TODO +0 -34
- data/VERSION +1 -1
- data/lib/lazylist.rb +18 -0
- data/tests/test.rb +41 -16
- metadata +36 -39
data/CHANGES
CHANGED
data/TODO
CHANGED
@@ -1,36 +1,2 @@
|
|
1
1
|
* adding better support for finite lazy lists
|
2
2
|
* make lists even
|
3
|
-
* this stuff
|
4
|
-
# XXX
|
5
|
-
def append(*elements)
|
6
|
-
return rest if empty?
|
7
|
-
s = self
|
8
|
-
loop do
|
9
|
-
if s.tail.empty?
|
10
|
-
break s
|
11
|
-
else
|
12
|
-
s = s.tail
|
13
|
-
end
|
14
|
-
end
|
15
|
-
s.tail = rest
|
16
|
-
self
|
17
|
-
end
|
18
|
-
alias << append
|
19
|
-
|
20
|
-
# XXX self should be finite
|
21
|
-
def +(other)
|
22
|
-
other.is_a? self.class or
|
23
|
-
raise TypeError, "other has to be a #{self.class}"
|
24
|
-
copy = LazyList[to_a]
|
25
|
-
s = copy
|
26
|
-
loop do
|
27
|
-
if s.tail.empty?
|
28
|
-
break s
|
29
|
-
else
|
30
|
-
s = s.tail
|
31
|
-
end
|
32
|
-
end
|
33
|
-
s.tail = LazyList[other.to_a]
|
34
|
-
copy
|
35
|
-
end
|
36
|
-
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/lazylist.rb
CHANGED
@@ -501,6 +501,24 @@ class LazyList
|
|
501
501
|
end
|
502
502
|
end
|
503
503
|
|
504
|
+
# Append this lazy list to the _*other_ lists, creating a new lists that
|
505
|
+
# consists of the elements of this list and the elements of the lists other1,
|
506
|
+
# other2, ... If any of the lists is infinite, the elements of the following
|
507
|
+
# lists will never occur in the result list.
|
508
|
+
def append(*other)
|
509
|
+
if empty?
|
510
|
+
if other.empty?
|
511
|
+
Empty
|
512
|
+
else
|
513
|
+
other.first.append(*other[1..-1])
|
514
|
+
end
|
515
|
+
else
|
516
|
+
list(head) { tail.append(*other) }
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
alias + append
|
521
|
+
|
504
522
|
# Takes the next n elements and returns them as an array.
|
505
523
|
def take(n = 1)
|
506
524
|
result = []
|
data/tests/test.rb
CHANGED
@@ -17,6 +17,8 @@ class MyEnum
|
|
17
17
|
end
|
18
18
|
|
19
19
|
class TC_LazyList < Test::Unit::TestCase
|
20
|
+
Empty = LazyList::Empty
|
21
|
+
|
20
22
|
def setup
|
21
23
|
@strings = LazyList.tabulate("a")
|
22
24
|
@natural = LazyList.tabulate(1)
|
@@ -37,7 +39,7 @@ class TC_LazyList < Test::Unit::TestCase
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def test_constructor
|
40
|
-
ll1 = LazyList.new(:foo,
|
42
|
+
ll1 = LazyList.new(:foo, Empty)
|
41
43
|
assert(!ll1.empty?)
|
42
44
|
ll2 = LazyList.new(:foo) { Empty }
|
43
45
|
assert(!ll2.empty?)
|
@@ -114,9 +116,9 @@ class TC_LazyList < Test::Unit::TestCase
|
|
114
116
|
end
|
115
117
|
|
116
118
|
def test_index
|
117
|
-
assert_equal nil,
|
118
|
-
assert_equal nil,
|
119
|
-
assert_equal nil,
|
119
|
+
assert_equal nil, Empty[-1]
|
120
|
+
assert_equal nil, Empty[0]
|
121
|
+
assert_equal nil, Empty[1]
|
120
122
|
assert @natural.cached?
|
121
123
|
assert_equal nil, @natural[-1]
|
122
124
|
assert_equal nil, @natural[-1]
|
@@ -138,10 +140,10 @@ class TC_LazyList < Test::Unit::TestCase
|
|
138
140
|
end
|
139
141
|
|
140
142
|
def test_index_without_cache
|
141
|
-
|
142
|
-
assert_equal nil,
|
143
|
-
assert_equal nil,
|
144
|
-
assert_equal nil,
|
143
|
+
Empty.cached = false
|
144
|
+
assert_equal nil, Empty[-1]
|
145
|
+
assert_equal nil, Empty[0]
|
146
|
+
assert_equal nil, Empty[1]
|
145
147
|
@natural.cached = false
|
146
148
|
assert !@natural.cached?
|
147
149
|
assert_equal nil, @natural[-1]
|
@@ -222,10 +224,10 @@ class TC_LazyList < Test::Unit::TestCase
|
|
222
224
|
end
|
223
225
|
|
224
226
|
def test_construct_ref
|
225
|
-
assert_equal
|
227
|
+
assert_equal Empty, LazyList[0, -1]
|
226
228
|
assert_equal [0], LazyList[0, 1].to_a
|
227
229
|
assert_equal (0..9).to_a, LazyList[0, 10].to_a
|
228
|
-
assert_equal
|
230
|
+
assert_equal Empty, LazyList[0..-1]
|
229
231
|
assert_equal [0], LazyList[0..0].to_a
|
230
232
|
assert_equal (0..9).to_a, LazyList[0..9].to_a
|
231
233
|
end
|
@@ -246,7 +248,7 @@ class TC_LazyList < Test::Unit::TestCase
|
|
246
248
|
|
247
249
|
def test_inspect
|
248
250
|
l = LazyList[1..11]
|
249
|
-
assert_equal "[]",
|
251
|
+
assert_equal "[]", Empty.inspect
|
250
252
|
assert_equal "[1,... ]", l.inspect
|
251
253
|
l[1]
|
252
254
|
assert_equal "[1, 2,... ]", l.inspect
|
@@ -273,11 +275,11 @@ class TC_LazyList < Test::Unit::TestCase
|
|
273
275
|
end
|
274
276
|
|
275
277
|
def test_list
|
276
|
-
assert_equal
|
278
|
+
assert_equal Empty, list
|
277
279
|
assert_equal [], list.to_a
|
278
|
-
assert_equal LazyList.new(1) {
|
280
|
+
assert_equal LazyList.new(1) { Empty }, list(1)
|
279
281
|
assert_equal [1], list(1).to_a
|
280
|
-
assert_equal
|
282
|
+
assert_equal Empty, list
|
281
283
|
o = odd
|
282
284
|
assert_equal [1, 3, 5, 7, 9, 11, 13, 15, 17, 19], o.take(10)
|
283
285
|
assert_equal @odd.take(10), o.take(10)
|
@@ -289,8 +291,8 @@ class TC_LazyList < Test::Unit::TestCase
|
|
289
291
|
end
|
290
292
|
|
291
293
|
def test_sublist
|
292
|
-
assert_equal
|
293
|
-
assert_equal
|
294
|
+
assert_equal Empty, @natural.sublist(-1)
|
295
|
+
assert_equal Empty, @natural.sublist(0)
|
294
296
|
assert_equal [1], @natural.sublist(1).to_a
|
295
297
|
assert_equal (1..10).to_a, @natural.sublist(10).to_a
|
296
298
|
assert_equal (6..15).to_a, @natural[5, 10].to_a
|
@@ -299,5 +301,28 @@ class TC_LazyList < Test::Unit::TestCase
|
|
299
301
|
assert_equal nil, @natural.sublist(10)[10]
|
300
302
|
assert_equal 10, @natural.sublist(10)[9]
|
301
303
|
end
|
304
|
+
|
305
|
+
def test_append
|
306
|
+
l1 = LazyList[1..3]
|
307
|
+
l2 = LazyList[5..7]
|
308
|
+
l3 = @natural.drop(8)
|
309
|
+
assert_equal [], Empty.append.to_a
|
310
|
+
assert_equal [], Empty.append(Empty).to_a
|
311
|
+
assert_equal [], (Empty + Empty).to_a
|
312
|
+
assert_equal [], Empty.append(Empty, Empty).to_a
|
313
|
+
assert_equal [1, 2, 3], Empty.append(Empty, l1).to_a
|
314
|
+
assert_equal [1, 2, 3], Empty.append(l1, Empty).to_a
|
315
|
+
assert_equal [1, 2, 3], Empty.append(Empty, l1, Empty).to_a
|
316
|
+
assert_equal [5, 6, 7, 1, 2, 3], l2.append(Empty, l1, Empty).to_a
|
317
|
+
assert_equal [1, 2, 3], l1.append.to_a
|
318
|
+
assert_equal [1, 2, 3], (l1 + Empty).to_a
|
319
|
+
assert_equal [1, 2, 3], (Empty + l1).to_a
|
320
|
+
assert_equal [1, 2, 3, 5, 6, 7], l1.append(l2).to_a
|
321
|
+
assert_equal [1, 2, 3, 5, 6, 7], (l1 + l2).to_a
|
322
|
+
assert_equal [1, 2, 3], l1.append(Empty).to_a
|
323
|
+
assert_equal [1, 2, 3], Empty.append(l1).to_a
|
324
|
+
assert_equal [1, 2, 3] + [5, 6, 7] + [9, 10, 11, 12],
|
325
|
+
l1.append(l2, l3).take(10)
|
326
|
+
end
|
302
327
|
end
|
303
328
|
# vim: set et sw=2 ts=2:
|
metadata
CHANGED
@@ -3,65 +3,62 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: lazylist
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2005-12-
|
6
|
+
version: 0.2.2
|
7
|
+
date: 2005-12-23 00:00:00 +01:00
|
8
8
|
summary: Implementation of lazy lists for Ruby
|
9
9
|
require_paths:
|
10
|
-
- lib
|
10
|
+
- lib
|
11
11
|
email: flori@ping.de
|
12
12
|
homepage: http://lazylist.rubyforge.org
|
13
13
|
rubyforge_project: lazylist
|
14
|
-
description:
|
14
|
+
description: ''
|
15
15
|
autorequire: lazylist
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
18
18
|
has_rdoc: true
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
20
|
requirements:
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
24
25
|
version:
|
25
26
|
platform: ruby
|
26
27
|
signing_key:
|
27
28
|
cert_chain:
|
28
29
|
authors:
|
29
|
-
- Florian Frank
|
30
|
+
- Florian Frank
|
30
31
|
files:
|
31
|
-
- examples
|
32
|
-
- install.rb
|
33
|
-
- GPL
|
34
|
-
- TODO
|
35
|
-
- Rakefile
|
36
|
-
- VERSION
|
37
|
-
- tests
|
38
|
-
- CHANGES
|
39
|
-
- lib
|
40
|
-
- make_doc.rb
|
41
|
-
- README.en
|
42
|
-
- examples/hamming.rb
|
43
|
-
- examples/sieve.rb
|
44
|
-
- examples/pi.rb
|
45
|
-
- examples/examples.rb
|
46
|
-
- tests/test.rb
|
47
|
-
- tests/test_enumerable.rb
|
48
|
-
- tests/runner.rb
|
49
|
-
- lib/lazylist.rb
|
32
|
+
- examples
|
33
|
+
- install.rb
|
34
|
+
- GPL
|
35
|
+
- TODO
|
36
|
+
- Rakefile
|
37
|
+
- VERSION
|
38
|
+
- tests
|
39
|
+
- CHANGES
|
40
|
+
- lib
|
41
|
+
- make_doc.rb
|
42
|
+
- README.en
|
43
|
+
- examples/hamming.rb
|
44
|
+
- examples/sieve.rb
|
45
|
+
- examples/pi.rb
|
46
|
+
- examples/examples.rb
|
47
|
+
- tests/test.rb
|
48
|
+
- tests/test_enumerable.rb
|
49
|
+
- tests/runner.rb
|
50
|
+
- lib/lazylist.rb
|
50
51
|
test_files:
|
51
|
-
- tests/test.rb
|
52
|
+
- tests/test.rb
|
52
53
|
rdoc_options:
|
53
|
-
- --title
|
54
|
-
- LazyList -- Infinite lists in Ruby
|
55
|
-
- --main
|
56
|
-
- LazyList
|
57
|
-
- --line-numbers
|
54
|
+
- "--title"
|
55
|
+
- "LazyList -- Infinite lists in Ruby"
|
56
|
+
- "--main"
|
57
|
+
- LazyList
|
58
|
+
- "--line-numbers"
|
58
59
|
extra_rdoc_files:
|
59
|
-
- lib/lazylist.rb
|
60
|
+
- lib/lazylist.rb
|
60
61
|
executables: []
|
61
|
-
|
62
62
|
extensions: []
|
63
|
-
|
64
63
|
requirements: []
|
65
|
-
|
66
|
-
dependencies: []
|
67
|
-
|
64
|
+
dependencies: []
|