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 +1 -0
- data/.travis.yml +2 -0
- data/CHANGES.md +14 -0
- data/lib/lazily/concatenating.rb +5 -0
- data/lib/lazily/enumerable.rb +1 -0
- data/lib/lazily/filtering.rb +16 -17
- data/lib/lazily/merging.rb +13 -0
- data/lib/lazily/version.rb +1 -1
- data/lib/lazily/zipping.rb +3 -1
- data/spec/lazily/bugs_spec.rb +9 -0
- data/spec/lazily/merging_spec.rb +2 -2
- data/spec/lazily/zipping_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -6
- metadata +15 -5
- checksums.yaml +0 -15
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
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".
|
data/lib/lazily/concatenating.rb
CHANGED
|
@@ -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
|
data/lib/lazily/enumerable.rb
CHANGED
data/lib/lazily/filtering.rb
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
247
|
-
@generator.call(yielder)
|
|
245
|
+
catch done do
|
|
246
|
+
@generator.call(yielder, done)
|
|
248
247
|
end
|
|
249
248
|
end
|
|
250
249
|
|
data/lib/lazily/merging.rb
CHANGED
|
@@ -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
|
data/lib/lazily/version.rb
CHANGED
data/lib/lazily/zipping.rb
CHANGED
|
@@ -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
|
data/spec/lazily/merging_spec.rb
CHANGED
data/spec/lazily/zipping_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
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.
|
|
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-
|
|
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:
|
|
78
|
+
rubygems_version: 1.8.23
|
|
70
79
|
signing_key:
|
|
71
|
-
specification_version:
|
|
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=
|