totally_lazy 0.1.56 → 0.1.57
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/totally_lazy/enumerators.rb +18 -0
- data/lib/totally_lazy/sequence.rb +4 -0
- data/spec/totally_lazy/sequence_spec.rb +8 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGU1OTQwMzdjMjU2YmU4NjQ3MGFlZDg4YmJhNjAyODdhOTA5MDIwOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzhkMjc2MjVhZTA0MGYzNDcwZTU0MDE5MGQ3NmU3YWVlYTJkZTBlNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTQ4ZDk2MzRkMzE5NWUwNDMzODIwMzM2MDFkYzRkNzA3Y2I5ODY3ODk3MjQ2
|
10
|
+
ZTUwYTNmYTNkNGY0NzAyNmRjZGY2NjJiZTIwMGFmNWE0YmY2NzFmMDdhYWE0
|
11
|
+
OWMwYTJkYmM4YTA5M2Y0ZGQzOWI4YWIzZWRiY2M2OWYyMGI5ZjY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2U0N2QyMTIzMGViMTczMmMzYjEyMjcwMGYxZjhhNjdiNThiOWM4YzAyYmVm
|
14
|
+
MDczNzA0ZmQxMzEzMDhlYzYwOGNmNGQ2NDI0OWVhOTYxMTg4YWZlM2E2OWI5
|
15
|
+
YjRjZjhmZjUxZGJjMGIyNWNkMjZjZDcwNTYwZTQ1ZmRlYjU1OGU=
|
@@ -72,6 +72,24 @@ module Enumerators
|
|
72
72
|
end.lazy
|
73
73
|
end
|
74
74
|
|
75
|
+
def enumerate(fn, start)
|
76
|
+
current = start
|
77
|
+
Enumerator.new do |y|
|
78
|
+
result = current
|
79
|
+
current = fn.(current)
|
80
|
+
y << result
|
81
|
+
end.lazy
|
82
|
+
end
|
83
|
+
|
84
|
+
def cycle_enumerator(e)
|
85
|
+
Enumerator.new do |y|
|
86
|
+
loop do
|
87
|
+
e.rewind unless has_next(e)
|
88
|
+
y << e.next
|
89
|
+
end
|
90
|
+
end.lazy
|
91
|
+
end
|
92
|
+
|
75
93
|
def empty_enumerator
|
76
94
|
[].lazy
|
77
95
|
end
|
@@ -288,21 +288,21 @@ describe 'Sequence' do
|
|
288
288
|
end
|
289
289
|
|
290
290
|
it 'should allow arrays to be converted to sequences' do
|
291
|
-
expect([1,2,3,4,5].to_seq).to eq(sequence(1,2,3,4,5))
|
291
|
+
expect([1, 2, 3, 4, 5].to_seq).to eq(sequence(1, 2, 3, 4, 5))
|
292
292
|
end
|
293
293
|
|
294
294
|
it 'should allow sequences to be converted to arrays' do
|
295
|
-
expect(sequence(1,2,3,4,5).to_a).to eq([1,2,3,4,5])
|
295
|
+
expect(sequence(1, 2, 3, 4, 5).to_a).to eq([1, 2, 3, 4, 5])
|
296
296
|
end
|
297
297
|
|
298
298
|
it 'should be able to display sequence as a string' do
|
299
|
-
expect(sequence(1,2,3,4,5).to_s).to eq('[1,2,3,4,5]')
|
299
|
+
expect(sequence(1, 2, 3, 4, 5).to_s).to eq('[1,2,3,4,5]')
|
300
300
|
expect(empty.to_s).to eq('[]')
|
301
301
|
expect(sequence(sequence(1)).flatten.to_s).to eq('[1]')
|
302
302
|
end
|
303
303
|
|
304
304
|
it 'should support join' do
|
305
|
-
expect(sequence(1,2,3).join(sequence(4,5,6))).to eq(sequence(1,2,3,4,5,6))
|
305
|
+
expect(sequence(1, 2, 3).join(sequence(4, 5, 6))).to eq(sequence(1, 2, 3, 4, 5, 6))
|
306
306
|
end
|
307
307
|
|
308
308
|
it 'should raise exception if you try to use both lambda and block' do
|
@@ -326,4 +326,8 @@ describe 'Sequence' do
|
|
326
326
|
expect { empty.group_by(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
|
327
327
|
expect { empty.each(->(v) { puts(v) }) { |v| puts(v) } }.to raise_error(RuntimeError)
|
328
328
|
end
|
329
|
+
|
330
|
+
it 'should support cycle' do
|
331
|
+
expect(range(1, 3).cycle.take(10)).to eq(sequence(1, 2, 3, 1, 2, 3, 1, 2, 3, 1))
|
332
|
+
end
|
329
333
|
end
|