ruby-stream 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  #ruby-stream
2
2
 
3
- [![Build Status](https://travis-ci.org/oetzi/ruby-stream.png?branch=master)](https://travis-ci.org/oetzi/ruby-stream)
3
+ [![Build Status](https://travis-ci.org/seadowg/ruby-stream.png?branch=master)](https://travis-ci.org/seadowg/ruby-stream)
4
4
 
5
5
  Lazy stream implementation for Ruby because Enumerators are kinda silly.
6
6
 
data/lib/ruby-stream.rb CHANGED
@@ -16,6 +16,15 @@ class Stream
16
16
  @tail_block.call
17
17
  end
18
18
 
19
+ def last
20
+ result = nil
21
+ self.each do |ele|
22
+ result = ele
23
+ end
24
+
25
+ result
26
+ end
27
+
19
28
  def [](n)
20
29
  if n == 0
21
30
  self.head
@@ -75,6 +84,12 @@ class Stream
75
84
  end
76
85
  end
77
86
 
87
+ def scan(zero, &block)
88
+ Stream.new(zero) do
89
+ tail.scan(block.call(zero, head), &block)
90
+ end
91
+ end
92
+
78
93
  def filter(&block)
79
94
  if block.call(head)
80
95
  Stream.new(head) do
data/ruby-stream.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.unshift lib unless $:.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ruby-stream"
6
- s.version = "0.2.0"
6
+ s.version = "0.3.0"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Callum Stott"]
9
9
  s.email = ["callum.stott@me.com"]
@@ -29,6 +29,12 @@ describe Stream do
29
29
  end
30
30
  end
31
31
 
32
+ describe "#last" do
33
+ it "returns the last element for finite Stream" do
34
+ @stream.take(5).last.must_equal 5
35
+ end
36
+ end
37
+
32
38
  describe "#[](n)" do
33
39
  it "calculates the nth element of the stream" do
34
40
  @stream[999].must_equal 1000
@@ -174,6 +180,24 @@ describe Stream do
174
180
  end
175
181
  end
176
182
 
183
+ describe "#scan(func)" do
184
+ it "returns a new Stream" do
185
+ @stream.scan(0) { |x, i| i }.kind_of?(Stream).must_equal true
186
+ end
187
+
188
+ it "returns a Stream with a head equivelant to the passed zero" do
189
+ @stream.scan(-1) { |x, i| i }.head.must_equal -1
190
+ end
191
+
192
+ it "returns a Stream where each element of the tail is the result of feeding the zero (or result) and function through to each of the original elements" do
193
+ scan = @stream.scan(0) { |x, i| x + i }
194
+ scan[1].must_equal(1)
195
+ scan[2].must_equal(3)
196
+ scan[3].must_equal(6)
197
+ scan[100].must_equal(5050)
198
+ end
199
+ end
200
+
177
201
  describe ".continually(func)" do
178
202
  it "returns a new Stream" do
179
203
  Stream.continually {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-08 00:00:00.000000000 Z
12
+ date: 2013-03-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: