totally_lazy 0.1.57 → 0.1.58

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGU1OTQwMzdjMjU2YmU4NjQ3MGFlZDg4YmJhNjAyODdhOTA5MDIwOA==
4
+ YzJmZGNkMjM1M2NhMGYwNjc0Y2UyZGQzYmMxOWQzODZjYmM0ZjE2MQ==
5
5
  data.tar.gz: !binary |-
6
- NzhkMjc2MjVhZTA0MGYzNDcwZTU0MDE5MGQ3NmU3YWVlYTJkZTBlNw==
6
+ NzI1ZGNmNjRmY2JhNDBjNjMyMjg1MWNkNTkwNWI2MGIzYzI1OGFmNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTQ4ZDk2MzRkMzE5NWUwNDMzODIwMzM2MDFkYzRkNzA3Y2I5ODY3ODk3MjQ2
10
- ZTUwYTNmYTNkNGY0NzAyNmRjZGY2NjJiZTIwMGFmNWE0YmY2NzFmMDdhYWE0
11
- OWMwYTJkYmM4YTA5M2Y0ZGQzOWI4YWIzZWRiY2M2OWYyMGI5ZjY=
9
+ ODdlMzk3MDE3NTA2YjFkZjJlMWIzZjhhY2UxM2VjZTU0N2U0NjdiMDQwNjlm
10
+ OTI5OTU5MTVmMGRiMGM5MDJhMTQ3ZDdmOWFjMjAzMWEyOTljMGMxOWIxMzI2
11
+ MjA5NDZlZjI2NDE0NmE3NmMwNTJhZDM2N2Y0ODllMzUzZGM3MmQ=
12
12
  data.tar.gz: !binary |-
13
- M2U0N2QyMTIzMGViMTczMmMzYjEyMjcwMGYxZjhhNjdiNThiOWM4YzAyYmVm
14
- MDczNzA0ZmQxMzEzMDhlYzYwOGNmNGQ2NDI0OWVhOTYxMTg4YWZlM2E2OWI5
15
- YjRjZjhmZjUxZGJjMGIyNWNkMjZjZDcwNTYwZTQ1ZmRlYjU1OGU=
13
+ MWJhMDFlZTU0ODY5MzBjMThlNzYzMDczOTA2MjYxMThjNWViODUxNWU2ODQw
14
+ MTg2MzVmOGM4ZTIzYWM1OWNlNzcwMzEyOGNhZWI2OWYyYWY2ZGI0ZTc5ZGIw
15
+ ZTgzODMzMzM1ZWRkN2I4NTBmNzk1YTUxNDgzNTQ4NWY2MDNlYjI=
@@ -73,11 +73,13 @@ module Enumerators
73
73
  end
74
74
 
75
75
  def enumerate(fn, start)
76
- current = start
77
76
  Enumerator.new do |y|
78
- result = current
79
- current = fn.(current)
80
- y << result
77
+ current = start
78
+ loop do
79
+ result = current
80
+ current = fn.(current)
81
+ y << result
82
+ end
81
83
  end.lazy
82
84
  end
83
85
 
@@ -47,4 +47,12 @@ module Numbers
47
47
  def greater_than(right)
48
48
  predicate(->(left) { left > right })
49
49
  end
50
+
51
+ def multiply(y)
52
+ monoid(->(x){x * y}, 1)
53
+ end
54
+
55
+ def powers_of(amount)
56
+ Sequence.new(enumerate(multiply(amount), 1))
57
+ end
50
58
  end
@@ -0,0 +1,15 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe 'Numbers' do
4
+ it 'should support arbitrary multiply' do
5
+ expect(sequence(1, 2, 3, 4, 5).map(multiply(5))).to eq(sequence(5, 10, 15, 20, 25))
6
+ end
7
+
8
+ it 'should treat multiply as a monoid' do
9
+ expect(empty.reduce(multiply(5))).to eq(1)
10
+ end
11
+
12
+ it 'should be able to get powers_of a number' do
13
+ expect(powers_of(3).take(10)).to eq(sequence(1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683))
14
+ end
15
+ 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.57
4
+ version: 0.1.58
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raymond Barlow
@@ -172,6 +172,7 @@ files:
172
172
  - spec/totally_lazy/either_spec.rb
173
173
  - spec/totally_lazy/functions_spec.rb
174
174
  - spec/totally_lazy/maps_spec.rb
175
+ - spec/totally_lazy/numbers_spec.rb
175
176
  - spec/totally_lazy/option_spec.rb
176
177
  - spec/totally_lazy/predicates_spec.rb
177
178
  - spec/totally_lazy/sequence_spec.rb