deferred_enum 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/deferred_enum.gemspec +1 -1
- data/lib/deferred_enum/map.rb +12 -0
- data/lib/deferred_enum/select.rb +12 -0
- data/lib/deferred_enum/version.rb +1 -1
- data/lib/deferred_enumerable.rb +7 -13
- data/lib/deferred_enumerator.rb +3 -0
- metadata +5 -3
data/deferred_enum.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "https://github.com/take-five/deferred_enum"
|
11
11
|
s.summary = %q{Introduces lazy computations to Enumerable}
|
12
12
|
s.description = File.read(File.expand_path('../README.rdoc', __FILE__))
|
13
|
-
s.date =
|
13
|
+
s.date = "2011-12-15"
|
14
14
|
|
15
15
|
s.rubyforge_project = "deferred_enum"
|
16
16
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class DeferredEnumerator::Select < DeferredEnumerator #:nodoc:all
|
2
|
+
def initialize(obj, filter = nil)
|
3
|
+
@_filter = filter
|
4
|
+
super(obj)
|
5
|
+
end
|
6
|
+
|
7
|
+
def each
|
8
|
+
return super unless block_given?
|
9
|
+
|
10
|
+
super { |e| yield(e) if !@_filter || @_filter.call(e) }
|
11
|
+
end
|
12
|
+
end
|
data/lib/deferred_enumerable.rb
CHANGED
@@ -27,32 +27,26 @@ module DeferredEnumerable
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Returns a new enumerator with the results of running block once for every element in enum.
|
30
|
-
def collect # :yields: obj
|
30
|
+
def collect(&block) # :yields: obj
|
31
31
|
return self unless block_given?
|
32
32
|
|
33
|
-
DeferredEnumerator.new
|
34
|
-
each { |entry| yielder << yield(entry) }
|
35
|
-
end
|
33
|
+
DeferredEnumerator::Map.new(self, block)
|
36
34
|
end
|
37
35
|
alias map collect
|
38
36
|
|
39
37
|
# Returns a enumerator containing all elements of enum for which block is not false
|
40
|
-
def select # :yields: obj
|
38
|
+
def select(&block) # :yields: obj
|
41
39
|
return self unless block_given?
|
42
40
|
|
43
|
-
DeferredEnumerator.new
|
44
|
-
each { |entry| yielder << entry if yield(entry) }
|
45
|
-
end
|
41
|
+
DeferredEnumerator::Select.new(self, block)
|
46
42
|
end
|
47
43
|
alias find_all select
|
48
44
|
|
49
45
|
# Returns a enumerator containing all elements of enum for which block is false
|
50
|
-
def reject # :yields: obj
|
46
|
+
def reject(&block) # :yields: obj
|
51
47
|
return self unless block_given?
|
52
48
|
|
53
|
-
|
54
|
-
each { |entry| yielder << entry unless yield(entry) }
|
55
|
-
end
|
49
|
+
select { |e| !block.call(e) }
|
56
50
|
end
|
57
51
|
|
58
52
|
# Returns a new enumerator that is a one-dimensional flattening of this enumerator (recursively).
|
@@ -125,7 +119,7 @@ module DeferredEnumerable
|
|
125
119
|
raise TypeError, 'Integer (> 0) expected' unless n.is_a?(Fixnum) && n > 0
|
126
120
|
|
127
121
|
DeferredEnumerator.new do |yielder|
|
128
|
-
each { |entry| yielder << entry if (n -= 1) >= 0}
|
122
|
+
each { |entry| yielder << entry if (n -= 1) >= 0 }
|
129
123
|
end
|
130
124
|
end
|
131
125
|
|
data/lib/deferred_enumerator.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alexey Mikhaylov
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-12-
|
17
|
+
date: 2011-12-15 00:00:00 +06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -82,6 +82,8 @@ files:
|
|
82
82
|
- deferred_enum.gemspec
|
83
83
|
- lib/deferred_enum.rb
|
84
84
|
- lib/deferred_enum/enumerable.rb
|
85
|
+
- lib/deferred_enum/map.rb
|
86
|
+
- lib/deferred_enum/select.rb
|
85
87
|
- lib/deferred_enum/version.rb
|
86
88
|
- lib/deferred_enumerable.rb
|
87
89
|
- lib/deferred_enumerator.rb
|