totally_lazy 0.1.36 → 0.1.37

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
- ZTAyZTdkODEyNmJlNmE4ZGY1Njk5NDdhZjAzMzhkNWMyMmIyOGJmZQ==
4
+ NzgwYzZmMGQ0YzA0OGNkZTdmN2JkYzFkNTgxODIzYTVjODUxNjhiYw==
5
5
  data.tar.gz: !binary |-
6
- ODBiYTI1MDQ4ZTRkNTM2YTFmOGZjZTgwZTMzYzg5NTUyNzllYmYxOQ==
6
+ ODdlYWJlMmFjYjc2MDY2NGU3OWIzMTdiYjNmMWM5ZTJjNWMyYzUwZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTQwMjYxYWFlNzBmZWExNTBmZjk4ZDhmNmNkY2NkMWE2NmU0ZDEyMjMzMjcy
10
- NDNlZDQ4ZWQzMzFkMjJkNmNkZjA3NjFhMzc5MzJjMjE2ODA0MjBhYjMxMDhk
11
- M2JjYmRiNzA5ODc2NzdkZDUyMjgwMzQxYWJiMGIzNDRkZTVhY2Y=
9
+ YTBhODEzNmM0OTFiMGNiZDIyMjg2OGFjNzBmMTUwOThlMjYxNWYxZDFjYWMx
10
+ YjE3ZWMyNjA0NDE5OTQwMTg4Y2RhOWEwZTVkMjM2ODY4YjM0MGIzMmU2NmEw
11
+ MjI0YmNjYWQzOTU0ZjY0OTZhYWNiNDliNTYyMWYwZTIxMjEzYzE=
12
12
  data.tar.gz: !binary |-
13
- MzdkMDUyYTIxNGVjOGQxNjI2MDA5NDdiY2IzNGNlZGIxNzdmOWNhOTYzNjI1
14
- MTVlNmI2OGViMzRmYzI5ZmE1NmZiNDQxYWNmYTYzZTIyYzAxMjZlYzEyM2E2
15
- ZGQxNzU5ZjA0ZGE5ZmYyYjQ4NTc5MTU5ZWI3N2QwOGQyYzA2ZTI=
13
+ MTAwYjk2YjAzMmU0ZWE4NmRjN2Y0OTdkYTMwOTgyY2IxM2I5NTBhNjM2ODY5
14
+ NjU0Zjc4NDNmY2Q0YWUxZjgzMmQ5MDg3YmUyYzVkYTZjY2I0OTU2MjMzODg0
15
+ OWJkNDZlZmJjNmVjMWNlZWY4ZTM1MzM4YzAwMDM3ZWNjOTM5OGM=
@@ -3,6 +3,12 @@ require_relative 'lambda_block'
3
3
  class NoSuchElementException < RuntimeError
4
4
  end
5
5
 
6
+ class Array
7
+ def to_seq
8
+ Sequence.new(self.lazy)
9
+ end
10
+ end
11
+
6
12
  module Sequences
7
13
  def empty
8
14
  Sequence.empty
@@ -205,28 +205,6 @@ describe 'Sequence' do
205
205
  expect(sequence(some(1), none, some(2)).flat_map { |s| s }).to eq(sequence(1, 2))
206
206
  end
207
207
 
208
- it 'should raise exception if you try to use both lambda and block' do
209
- expect { empty.map(->(a) { a+1 }) { |b| b+2 } }.to raise_error(RuntimeError)
210
- expect { empty.map_concurrently(->(a) { a+1 }) { |b| b+2 } }.to raise_error(RuntimeError)
211
- expect { empty.flat_map(->(a) { a+1 }) { |b| b+2 } }.to raise_error(RuntimeError)
212
- expect { empty.fold(0, ->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
213
- expect { empty.fold_left(0, ->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
214
- expect { empty.fold_right(0, ->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
215
- expect { empty.reduce(->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
216
- expect { empty.reduce_left(->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
217
- expect { empty.reduce_right(->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
218
- expect { empty.find(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
219
- expect { empty.find_index_of(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
220
- expect { empty.take_while(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
221
- expect { empty.drop_while(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
222
- expect { empty.exists?(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
223
- expect { empty.for_all?(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
224
- expect { empty.filter(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
225
- expect { empty.reject(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
226
- expect { empty.group_by(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
227
- expect { empty.each(->(v) { puts(v) }) { |v| puts(v) } }.to raise_error(RuntimeError)
228
- end
229
-
230
208
  it 'should support flatten' do
231
209
  expect(sequence('Hello').map(to_characters).flatten).to eq(sequence('H', 'e', 'l', 'l', 'o'))
232
210
  expect(sequence(some(1), none, some(3)).flatten).to eq(sequence(1, 3))
@@ -301,4 +279,30 @@ describe 'Sequence' do
301
279
  strings_block = sequence(1, 2).map_concurrently { |value| to_string.(value) }
302
280
  expect(strings_block).to eq(sequence('1', '2'))
303
281
  end
282
+
283
+ it 'should allow arrays to be converted to sequences' do
284
+ expect([1,2,3,4,5].to_seq).to eq(sequence(1,2,3,4,5))
285
+ end
286
+
287
+ it 'should raise exception if you try to use both lambda and block' do
288
+ expect { empty.map(->(a) { a+1 }) { |b| b+2 } }.to raise_error(RuntimeError)
289
+ expect { empty.map_concurrently(->(a) { a+1 }) { |b| b+2 } }.to raise_error(RuntimeError)
290
+ expect { empty.flat_map(->(a) { a+1 }) { |b| b+2 } }.to raise_error(RuntimeError)
291
+ expect { empty.fold(0, ->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
292
+ expect { empty.fold_left(0, ->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
293
+ expect { empty.fold_right(0, ->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
294
+ expect { empty.reduce(->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
295
+ expect { empty.reduce_left(->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
296
+ expect { empty.reduce_right(->(a, b) { a+b }) { |a, b| a+b } }.to raise_error(RuntimeError)
297
+ expect { empty.find(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
298
+ expect { empty.find_index_of(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
299
+ expect { empty.take_while(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
300
+ expect { empty.drop_while(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
301
+ expect { empty.exists?(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
302
+ expect { empty.for_all?(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
303
+ expect { empty.filter(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
304
+ expect { empty.reject(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
305
+ expect { empty.group_by(->(_) { true }) { |_| true } }.to raise_error(RuntimeError)
306
+ expect { empty.each(->(v) { puts(v) }) { |v| puts(v) } }.to raise_error(RuntimeError)
307
+ end
304
308
  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.36
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raymond Barlow