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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmQyN2I0MzM0NzY5NjEyZGM4NDJmMzAwNzMwY2JiZjM2ZGY5ZThmOQ==
4
+ ZGU1OTQwMzdjMjU2YmU4NjQ3MGFlZDg4YmJhNjAyODdhOTA5MDIwOA==
5
5
  data.tar.gz: !binary |-
6
- NDFhNDU0YzYxNjcwMjdlNmZmZjhlZTllYTIzNTAyMzZmMDMyYmZkZQ==
6
+ NzhkMjc2MjVhZTA0MGYzNDcwZTU0MDE5MGQ3NmU3YWVlYTJkZTBlNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGY0ZDg4NTE0M2Q5YmM0YmJlM2I1N2YxNmIxNzJiMTRmOTE2YjViMmRjMzc2
10
- NjMxYmFmMWUwYmViNTllMTIzMWM2ZGFjYjU5NzI2YjYxZGIyNTI3OWJjMjMz
11
- YjRmMGE5NDhlODg2ZTVlMDdjYTk1OTgyOGMyOTEwMzQyNzE1NGY=
9
+ MTQ4ZDk2MzRkMzE5NWUwNDMzODIwMzM2MDFkYzRkNzA3Y2I5ODY3ODk3MjQ2
10
+ ZTUwYTNmYTNkNGY0NzAyNmRjZGY2NjJiZTIwMGFmNWE0YmY2NzFmMDdhYWE0
11
+ OWMwYTJkYmM4YTA5M2Y0ZGQzOWI4YWIzZWRiY2M2OWYyMGI5ZjY=
12
12
  data.tar.gz: !binary |-
13
- NjkxMTNhMDlmMWNmZjI5MmNkODE3YjY0YWM1ZmRmYmFlNzE0YWM1MzYyM2Yx
14
- Y2M1ZDYwYmQzZDE5NGQ0MTE2YzliYWI3YzBlYWU5YmQxNTg5OTRhYjVkYzQz
15
- NDZlZGVhMGFkOGI3MjcwNzViMmRhOGRkYWI3NGMyMjNiMjRkY2Y=
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
@@ -311,6 +311,10 @@ class Sequence
311
311
  end.lazy)
312
312
  end
313
313
 
314
+ def cycle
315
+ Sequence.new(cycle_enumerator(@enumerator))
316
+ end
317
+
314
318
  def to_a
315
319
  @enumerator.to_a
316
320
  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
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.56
4
+ version: 0.1.57
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raymond Barlow