hamster 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +4 -0
- data/README.rdoc +1 -1
- data/lib/hamster/list.rb +6 -2
- data/lib/hamster/version.rb +1 -1
- data/spec/hamster/list/empty_spec.rb +12 -0
- metadata +2 -2
data/History.rdoc
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
=== 0.2.1 / 2010-01-15
|
2
|
+
|
3
|
+
* Fix bug: List#empty? would cause a stack overflow on very large streams.
|
4
|
+
|
1
5
|
=== 0.2.0 / 2010-01-14
|
2
6
|
|
3
7
|
* List methods that return lists are now all lazy. Not sure what, if any, negative impact this will have but the positives have so far been well worth it.
|
data/README.rdoc
CHANGED
@@ -122,7 +122,7 @@ The following code will only call <tt>prime?</tt> as many times as necessary to
|
|
122
122
|
|
123
123
|
Compare that to the conventional equivalent which needs to calculate all possible values in the range before taking the first 3:
|
124
124
|
|
125
|
-
(10000..1000000).select { |i| prime?(i) }
|
125
|
+
(10000..1000000).select { |i| prime?(i) }.take(3) # => 10s
|
126
126
|
|
127
127
|
Besides <tt>Hamster.list</tt> there are other ways to construct lists:
|
128
128
|
|
data/lib/hamster/list.rb
CHANGED
@@ -488,10 +488,14 @@ module Hamster
|
|
488
488
|
end
|
489
489
|
|
490
490
|
def empty?
|
491
|
-
target
|
491
|
+
list = target
|
492
|
+
while list.is_a?(Stream)
|
493
|
+
list = list.target
|
494
|
+
end
|
495
|
+
list.empty?
|
492
496
|
end
|
493
497
|
|
494
|
-
|
498
|
+
protected
|
495
499
|
|
496
500
|
def target
|
497
501
|
@mutex.synchronize do
|
data/lib/hamster/version.rb
CHANGED
@@ -8,6 +8,18 @@ describe Hamster::List do
|
|
8
8
|
|
9
9
|
describe "##{method}" do
|
10
10
|
|
11
|
+
describe "on a really big list" do
|
12
|
+
|
13
|
+
before do
|
14
|
+
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "doesn't run out of stack" do
|
18
|
+
lambda { @list.filter(&:nil?).empty? }.should_not raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
11
23
|
[
|
12
24
|
[[], true],
|
13
25
|
[["A"], false],
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Harris
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-15 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|