totally_lazy 0.1.30 → 0.1.31

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
- ZTQ2YmVkZDgxNGZlNzM3M2JkMzZmMmEyM2NhNTgwZGRlMGExMDE2Mw==
4
+ Y2UwOTI4NzkzYjg5ODZlN2MxNDJlYzdhMGE0MGUzYzRmNmZkNzM2Zg==
5
5
  data.tar.gz: !binary |-
6
- NjMzYTViMTYzMzNmNGRkMTg1ZGQyM2E5ODc2M2E3Zjg3ZmZkZWJmMA==
6
+ MTZjNjBkYTU5ZGI4ODJjNjkwMDU1MzE0NWQwNDJiYzliNDEwZWNlZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmY4Njg5Mzc0NThhMjI1OWNmMmU4ODY3YmU2ODY1MTlmZjlhMWNkZDcyOWMw
10
- ZjQ4NDNlYjY1NWM2ZTQyNGJhMjYxMzA5NDMzMjQzODI0ZDlmZTZlYTk4NTBm
11
- ZGVhYmQ5YzdjMTg3NDgyZWI3NzkyMmZiNWFjYTgyOWUwM2VjMTU=
9
+ NjE0YTY1YzYwZGZkZmJhN2NjYjdkMDQwMDY5YzBlMDkxYTFiYTAyYWFkNWQw
10
+ YzNjOTcxZWU0ZTQwOGVjMzJhZWYzMTE4YWU3MDEwZGZiNTE2ZDQ5N2I0OGZk
11
+ YzljMmRlM2Q5Y2U4MWQ5ZjMxYmE2ZTJjOTM0OTg1MDA5NjAxZTg=
12
12
  data.tar.gz: !binary |-
13
- NTI4YmJlNmIwMGE3YTZkZGIxODEzZjE4MmYwMDk2NmViYzJmOTVmNzRkYTVj
14
- YmNmZTcwNDhmYTAwZGI0NjU1ZTJlNzRmYWQ5YTAzMThjNjk2NDU4NWViMmVk
15
- MjJmZDIzYTMyMWFhYmZmZDNhZDcyZDQxMjBjYTZjM2U3NTVlNWM=
13
+ MWZmZTgwNTM5NWRiY2VjZTI2MWRiMTUzMTRhYThiZWU5MmE3MzQ5YzJlMTBh
14
+ YjBhMjE2M2UzNTQ1YTlkODA3MDFiYWJhMWZlNzFkZTRiZWFmNjYwMWI2Njc3
15
+ ZjI3N2Y5MjJlMDM2NDM1MTYyNDBkNzU2MjRhYTQ5MjAyYjY1ZTk=
@@ -73,7 +73,12 @@ class Left < Either
73
73
  def flat_map(fn=nil, &block) # a function which returns an either
74
74
  assert_funcs(fn, block_given?)
75
75
  self
76
- end
76
+ end
77
+
78
+ def fold(seed, fn_left, fn_right)
79
+ fn_left.(seed, @value)
80
+ end
81
+
77
82
  def <=>(other)
78
83
  @value <=> other.left_value
79
84
  end
@@ -119,6 +124,10 @@ class Right < Either
119
124
  block_given? ? block.call(@value) : fn.(@value)
120
125
  end
121
126
 
127
+ def fold(seed, fn_left, fn_right)
128
+ fn_right.(seed, @value)
129
+ end
130
+
122
131
  def <=>(other)
123
132
  @value <=> other.right_value
124
133
  end
@@ -40,6 +40,11 @@ describe 'Either' do
40
40
  expect(right(right(1)).flatten).to eq(right(1))
41
41
  end
42
42
 
43
+ it 'should support fold' do
44
+ expect(left(3).fold(2, sum, nil)).to eq(5)
45
+ expect(right(3).fold(2, nil, sum)).to eq(5)
46
+ end
47
+
43
48
  it 'should raise exception if you try to use both lambda and block' do
44
49
  expect { right(1).map(add(2)) { |a| a+2 } }.to raise_error(RuntimeError)
45
50
  expect { right(1).map_left(add(2)) { |a| a+2 } }.to raise_error(RuntimeError)
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.30
4
+ version: 0.1.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raymond Barlow