lazily 0.1.0 → 0.1.1

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/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  .bundle
3
+ .rbx
3
4
  .yardoc
4
5
  Gemfile.lock
5
6
  doc
@@ -5,3 +5,5 @@ rvm:
5
5
  - 2.0.0
6
6
  - jruby-18mode
7
7
  - jruby-19mode
8
+ - rbx-18mode
9
+ - rbx-19mode
data/CHANGES.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1 (2013-05-06)
4
+
5
+ * Get lazy `#zip` working in Ruby 1.8.7.
6
+ * Bug-fix: #prefetch and #take were interacting badly.
7
+ * Make it all work in Rubinius.
8
+
9
+ ## 0.1.0 (2013-05-13)
10
+
11
+ * Implement lazy versions of: `#grep`, `#collect_contact`, `#flatten` and `#compact`.
12
+ * Make `#chunk` and `#slice_before` lazy.
13
+ * Remove `#merge_by` in favour of enhanced `#merge`.
14
+ * Remove `#uniq_by` in favour of enhanced `#uniq`.
15
+ * Much refactoring.
16
+
3
17
  ## 0.0.1 (2013-04-19)
4
18
 
5
19
  * Initial version, ported from "enumerating".
@@ -9,6 +9,11 @@ module Lazily
9
9
  # @param enumerables [Array<Enumerable>]
10
10
  # @return [Enumerable] elements of all the enumerables
11
11
  #
12
+ # @example
13
+ # array1 = [1,4,5]
14
+ # array2 = [2,3,6]
15
+ # Lazily.concat(array1, array2) #=> [1,4,5,2,3,6]
16
+ #
12
17
  def concat(*enumerables)
13
18
  Concatenator.new(enumerables)
14
19
  end
@@ -4,6 +4,7 @@ module Lazily
4
4
 
5
5
  include ::Enumerable
6
6
 
7
+ # @return true
7
8
  def lazy?
8
9
  true
9
10
  end
@@ -10,7 +10,7 @@ module Lazily
10
10
  # @see ::Enumerable#collect
11
11
  #
12
12
  def collect(&transformation)
13
- filter("collect") do |output|
13
+ filter("collect") do |output, done|
14
14
  each do |element|
15
15
  output.call yield(element)
16
16
  end
@@ -26,7 +26,7 @@ module Lazily
26
26
  # @see ::Enumerable#select
27
27
  #
28
28
  def select(&predicate)
29
- filter("select") do |output|
29
+ filter("select") do |output, done|
30
30
  each do |element|
31
31
  output.call(element) if yield(element)
32
32
  end
@@ -44,7 +44,7 @@ module Lazily
44
44
  # @see ::Enumerable#reject
45
45
  #
46
46
  def reject
47
- filter("reject") do |output|
47
+ filter("reject") do |output, done|
48
48
  each do |element|
49
49
  output.call(element) unless yield(element)
50
50
  end
@@ -61,7 +61,7 @@ module Lazily
61
61
  # @see ::Enumerable#uniq
62
62
  #
63
63
  def uniq
64
- filter("uniq") do |output|
64
+ filter("uniq") do |output, done|
65
65
  seen = Set.new
66
66
  each do |element|
67
67
  key = if block_given?
@@ -82,11 +82,11 @@ module Lazily
82
82
  # @see ::Enumerable#take
83
83
  #
84
84
  def take(n)
85
- filter("take") do |output|
85
+ filter("take") do |output, done|
86
86
  if n > 0
87
87
  each_with_index do |element, index|
88
88
  output.call(element)
89
- throw Filter::DONE if index + 1 == n
89
+ throw done if index + 1 == n
90
90
  end
91
91
  end
92
92
  end
@@ -99,9 +99,9 @@ module Lazily
99
99
  # @see ::Enumerable#take_while
100
100
  #
101
101
  def take_while(&predicate)
102
- filter("take_while") do |output|
102
+ filter("take_while") do |output, done|
103
103
  each do |element|
104
- throw Filter::DONE unless yield(element)
104
+ throw done unless yield(element)
105
105
  output.call(element)
106
106
  end
107
107
  end
@@ -115,7 +115,7 @@ module Lazily
115
115
  # @see ::Enumerable#drop
116
116
  #
117
117
  def drop(n)
118
- filter("drop") do |output|
118
+ filter("drop") do |output, done|
119
119
  each_with_index do |element, index|
120
120
  next if index < n
121
121
  output.call(element)
@@ -130,7 +130,7 @@ module Lazily
130
130
  # @see ::Enumerable#drop_while
131
131
  #
132
132
  def drop_while(&predicate)
133
- filter("drop_while") do |output|
133
+ filter("drop_while") do |output, done|
134
134
  take = false
135
135
  each do |element|
136
136
  take ||= !yield(element)
@@ -146,7 +146,7 @@ module Lazily
146
146
  # @see ::Enumerable#grep
147
147
  #
148
148
  def grep(pattern)
149
- filter("grep") do |output|
149
+ filter("grep") do |output, done|
150
150
  each do |element|
151
151
  if pattern === element
152
152
  result = if block_given?
@@ -167,7 +167,7 @@ module Lazily
167
167
  # @see ::Array#flatten
168
168
  #
169
169
  def flatten(level = 1)
170
- filter("flatten") do |output|
170
+ filter("flatten") do |output, done|
171
171
  each do |element|
172
172
  if level > 0 && element.respond_to?(:each)
173
173
  element.flatten(level - 1).each(&output)
@@ -191,7 +191,7 @@ module Lazily
191
191
  # @see ::Array#compact
192
192
  #
193
193
  def compact
194
- filter("compact") do |output|
194
+ filter("compact") do |output, done|
195
195
  each do |element|
196
196
  output.call(element) unless element.nil?
197
197
  end
@@ -238,13 +238,12 @@ module Lazily
238
238
  @generator = generator
239
239
  end
240
240
 
241
- DONE = "Lazily::DONE".to_sym
242
-
243
241
  def each
242
+ done = "done-#{object_id}".to_sym
244
243
  return to_enum unless block_given?
245
244
  yielder = proc { |x| yield x }
246
- catch DONE do
247
- @generator.call(yielder)
245
+ catch done do
246
+ @generator.call(yielder, done)
248
247
  end
249
248
  end
250
249
 
@@ -4,6 +4,19 @@ module Lazily
4
4
 
5
5
  class << self
6
6
 
7
+ # Merge a number of sorted Enumerables into a single sorted collection.
8
+ #
9
+ # Draws elements from enumerables as appropriate, to preserve the sort order. An optional block, if provided, is used for comparison of elements.
10
+ # Otherwise, natural element order is used.
11
+ #
12
+ # @param enumerables [Array<Enumerable>]
13
+ # @return [Enumerable] merged, sorted elements
14
+ #
15
+ # @example
16
+ # array1 = [1,4,5]
17
+ # array2 = [2,3,6]
18
+ # Lazily.merge(array1, array2) #=> [1,2,3,4,5,6]
19
+ #
7
20
  def merge(*enumerables, &block)
8
21
  Merger.new(enumerables, &block)
9
22
  end
@@ -1,3 +1,3 @@
1
1
  module Lazily
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.1".freeze
3
3
  end
@@ -28,11 +28,13 @@ module Lazily
28
28
 
29
29
  def each
30
30
  enumerators = @enumerables.map(&:to_enum)
31
+ exhausted = {}
31
32
  while true
32
33
  chunk = enumerators.map do |enumerator|
33
34
  begin
34
- enumerator.next
35
+ enumerator.next unless exhausted[enumerator]
35
36
  rescue StopIteration
37
+ exhausted[enumerator] = true
36
38
  nil
37
39
  end
38
40
  end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe Lazily, "squashing bugs" do
4
+
5
+ example "#prefetch and #take interact well" do
6
+ [1,2,3].lazily.take(3).prefetch(2).take(1).to_a.should == [1]
7
+ end
8
+
9
+ end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Lazily, :needs_enumerators => true do
3
+ describe Lazily do
4
4
 
5
5
  describe ".merge" do
6
6
 
@@ -32,4 +32,4 @@ describe Lazily, :needs_enumerators => true do
32
32
 
33
33
  end
34
34
 
35
- end
35
+ end if defined?(::Enumerator)
@@ -1,10 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Lazily, "zipping", :needs_enumerators => true do
3
+ describe Lazily, "zipping" do
4
4
 
5
5
  let(:array1) { [1,3,6] }
6
6
  let(:array2) { [2,4,7] }
7
- let(:array3) { [5,8] }
7
+ let(:array3) { [5] }
8
8
 
9
9
  describe ".zip" do
10
10
 
@@ -33,9 +33,3 @@ module Enumerable
33
33
  end
34
34
 
35
35
  end
36
-
37
- RSpec.configure do |config|
38
- unless defined?(::Enumerator)
39
- config.filter_run_excluding :needs_enumerators => true
40
- end
41
- end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazily
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Mike Williams
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-05-13 00:00:00.000000000 Z
12
+ date: 2013-05-16 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: ! " Lazily implements \"lazy\" versions of many Enumerable methods,\n
14
15
  \ allowing streamed processing of large (or even infinite) collections.\n\n It's
@@ -39,6 +40,7 @@ files:
39
40
  - lib/lazily/threading.rb
40
41
  - lib/lazily/version.rb
41
42
  - lib/lazily/zipping.rb
43
+ - spec/lazily/bugs_spec.rb
42
44
  - spec/lazily/concatenating_spec.rb
43
45
  - spec/lazily/filtering_spec.rb
44
46
  - spec/lazily/merging_spec.rb
@@ -49,28 +51,36 @@ files:
49
51
  - spec/spec_helper.rb
50
52
  homepage: http://github.com/mdub/lazily
51
53
  licenses: []
52
- metadata: {}
53
54
  post_install_message:
54
55
  rdoc_options: []
55
56
  require_paths:
56
57
  - lib
57
58
  required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
58
60
  requirements:
59
61
  - - ! '>='
60
62
  - !ruby/object:Gem::Version
61
63
  version: '0'
64
+ segments:
65
+ - 0
66
+ hash: -3464940325120125091
62
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
63
69
  requirements:
64
70
  - - ! '>='
65
71
  - !ruby/object:Gem::Version
66
72
  version: '0'
73
+ segments:
74
+ - 0
75
+ hash: -3464940325120125091
67
76
  requirements: []
68
77
  rubyforge_project:
69
- rubygems_version: 2.0.0
78
+ rubygems_version: 1.8.23
70
79
  signing_key:
71
- specification_version: 4
80
+ specification_version: 3
72
81
  summary: Lazy Enumerables for everybody!
73
82
  test_files:
83
+ - spec/lazily/bugs_spec.rb
74
84
  - spec/lazily/concatenating_spec.rb
75
85
  - spec/lazily/filtering_spec.rb
76
86
  - spec/lazily/merging_spec.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTA2Zjk3MzAxNDg4N2JhMGFhZDAyNTJjZmQ3YzExYzFkNDA4NmZlMw==
5
- data.tar.gz: !binary |-
6
- YmY5MzM3N2ZiYTZkZWVjNzMzNTE2NjhjMmQ1NDZhN2UyYjgxODcxOQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- OThlZDA3NGU5ZTAzMmUxZjY0ZmJkMGU3OGE0MDZhZGE0ZTE5NDI5ZDBlZmVi
10
- ODFmYjEyYmVmNGUwYmMwMzllYjU0NGUwMTgwN2I5NTc5NjExM2U1MTI0MmY3
11
- ZjYyOTJiZTMwN2I1ZGMwNmUzYWM5ZWZkMmZjZjJhYTkxOWRlYzI=
12
- data.tar.gz: !binary |-
13
- NDA3OTM0ZWMzOGNkMDY3M2JjNmYwYzg2Zjk4NmY0MjNlZDY2ZWZkY2I0NzMx
14
- Y2E5MzJmODU5MTgyYTk4MjUxZWIxYWQwNzM5NjExNWRhNDFhYTgzYjM3NGE3
15
- Yzk5NjVmMjBjMjBkMDcyZmM2YTAwNzI1YzcwZTA1NTBiZmIyZDM=