totally_lazy 0.1.11 → 0.1.12
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.
- checksums.yaml +8 -8
- data/Rakefile +1 -1
- data/lib/functions.rb +7 -0
- data/lib/numbers.rb +1 -2
- data/lib/sequence.rb +18 -6
- data/lib/strings.rb +1 -1
- data/spec/sequence_spec.rb +6 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzNiZGM3ZGU2ODAwMTFlZjMxYzg2NzAxYzI5YzA2YzU5YmQyZGNlMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGQ5ZDc1ZTQ4YWFkZmExMzJlMDAwMGI2NTEwYjA1MWMxZDQxY2JmOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzZjYzZiNTI1M2QwMjNmNGRmNjQzYjA1NjY3YTUxNDk3OTNlYjQ1NTAwNzU3
|
10
|
+
NzlmNGZiZWQxMDNkNDNmNGUxMTQ0MTYxMGE2NGRhMTcwMDg2MjExOTI5NGU4
|
11
|
+
ODZmZTVlN2YyMTAzZDQ4ZTZhY2E1ODU2MTdiNDJiOGZiNDI3YTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGI0ZjdmYWQ0MjViOWU4Y2Q2ODdmYjlkYTUxNWFkOGM5MDAwNDIyM2MxN2Vm
|
14
|
+
NjJkN2FhZWE3ZWMxN2U4ZmQ0MzI0NGY1NDlkNzE5MDFiZGQxOWFhZjk2MDlh
|
15
|
+
OWNiNDVmZjZhOTk1OWRiN2ZiOWVlODdlZmI2YWFkMDkxZWQzOTI=
|
data/Rakefile
CHANGED
@@ -24,7 +24,7 @@ task :guard do
|
|
24
24
|
system('bundle exec guard')
|
25
25
|
end
|
26
26
|
|
27
|
-
version = "#{File.read('VERSION').to_s}.#{ENV['BUILD_NUMBER'].to_s}"
|
27
|
+
version = "#{File.read('VERSION').to_s}.#{ENV['BUILD_NUMBER'].nil? ? 'devbuild' : ENV['BUILD_NUMBER'].to_s}"
|
28
28
|
|
29
29
|
require 'jeweler'
|
30
30
|
Jeweler::Tasks.new do |gem|
|
data/lib/functions.rb
CHANGED
data/lib/numbers.rb
CHANGED
data/lib/sequence.rb
CHANGED
@@ -128,18 +128,25 @@ module Sequences
|
|
128
128
|
|
129
129
|
def reduce(fn=nil, &block)
|
130
130
|
assert_funcs(fn, block_given?)
|
131
|
-
|
132
|
-
|
133
|
-
|
131
|
+
_fn = block_given? ? ->(a, b) { block.call(a, b) } : fn
|
132
|
+
accumulator = seed(@enumerator, fn)
|
133
|
+
while has_next(@enumerator)
|
134
|
+
accumulator = _fn.(accumulator, @enumerator.next)
|
135
|
+
end
|
136
|
+
accumulator
|
134
137
|
end
|
135
138
|
|
136
139
|
alias reduce_left reduce
|
137
140
|
|
138
141
|
def reduce_right(fn=nil, &block)
|
139
142
|
assert_funcs(fn, block_given?)
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
+
_fn = block_given? ? ->(a, b) { block.call(a, b) } : fn
|
144
|
+
reversed = Enumerators::reverse(@enumerator)
|
145
|
+
accumulator = seed(reversed, fn)
|
146
|
+
while has_next(reversed)
|
147
|
+
accumulator = _fn.(reversed.next, accumulator)
|
148
|
+
end
|
149
|
+
accumulator
|
143
150
|
end
|
144
151
|
|
145
152
|
def find(fn_pred=nil, &block_pred)
|
@@ -251,6 +258,11 @@ module Sequences
|
|
251
258
|
def assert_funcs(fn, block_given)
|
252
259
|
raise 'Cannot pass both lambda and block expressions' if !fn.nil? && block_given
|
253
260
|
end
|
261
|
+
|
262
|
+
def seed(enumerator, fn)
|
263
|
+
enumerator.rewind
|
264
|
+
!fn.nil? && fn.respond_to?(:identity) ? fn.identity : enumerator.next
|
265
|
+
end
|
254
266
|
end
|
255
267
|
|
256
268
|
def group(key, enumerator)
|
data/lib/strings.rb
CHANGED
data/spec/sequence_spec.rb
CHANGED
@@ -104,6 +104,10 @@ describe 'Sequence' do
|
|
104
104
|
expect(sequence('1', '2', '3').reduce_left(join)).to eq('123')
|
105
105
|
end
|
106
106
|
|
107
|
+
it 'should support reduce of empty sequence' do
|
108
|
+
expect(empty.reduce(sum)).to eq(0)
|
109
|
+
end
|
110
|
+
|
107
111
|
it 'should support fold_right' do
|
108
112
|
expect(empty.fold_right(4, sum)).to eq(4)
|
109
113
|
expect(sequence(1).fold_right(4, sum)).to eq(5)
|
@@ -117,12 +121,12 @@ describe 'Sequence' do
|
|
117
121
|
end
|
118
122
|
|
119
123
|
it 'should support reduce_right' do
|
120
|
-
|
124
|
+
expect(empty.reduce_right(sum)).to eq(0)
|
121
125
|
expect(sequence(1).reduce_right(sum)).to eq(1)
|
122
126
|
expect(sequence(1, 2).reduce_right(sum)).to eq(3)
|
123
127
|
expect(sequence(1, 2, 3).reduce_right(sum)).to eq(6)
|
124
128
|
expect(sequence(1, 2, 3).reduce_right { |a, b| a+b }).to eq(6)
|
125
|
-
|
129
|
+
expect(empty.reduce_right(join)).to eq('')
|
126
130
|
expect(sequence('1').reduce_right(join)).to eq('1')
|
127
131
|
expect(sequence('1', '2').reduce_right(join)).to eq('12')
|
128
132
|
expect(sequence('1', '2', '3').reduce_right(join)).to eq('123')
|
@@ -296,6 +300,4 @@ describe 'Sequence' do
|
|
296
300
|
strings_block = sequence(1, 2).map_concurrently { |value| to_string.(value) }
|
297
301
|
expect(strings_block).to eq(sequence('1', '2'))
|
298
302
|
end
|
299
|
-
|
300
|
-
|
301
303
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: totally_lazy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raymond Barlow
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-02-
|
12
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|