abstractivator 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8929bafe047d7ee344331b015c9408ba151b27b5
4
- data.tar.gz: cbaa2ac79d3581202fc89adeecdfd5a488df91b7
3
+ metadata.gz: b63dfde1120e13e9caa680503d426bc9920cf71a
4
+ data.tar.gz: 9067bc5629954a5e2a693b91095d759ce3131602
5
5
  SHA512:
6
- metadata.gz: 8e938f5a2e3cbb2ae6e672accdde64dd4fd3b35f87923babbc49163dc4c1dc54b569ef696eea944d08db74643aedff81d6811583f8cf282715228a6e30ab2ca0
7
- data.tar.gz: ccde9bcc6996de8d961056a6db883c4801e875a2e3ea069b379636f92c299055d2f95d0daced4d6f4214f54c7a587e2d788249f69dd560d05b58ebaaf815a0bd
6
+ metadata.gz: dbc09f02c2159b81340c2ab7b0c55fa5f508595f753297534f23dff33e974ff33449889abfa3014f973cd0cc47413e1a2d85dfd7fa89392d25e4bf7027ec6c13
7
+ data.tar.gz: ad28b8056c20f5f3b31a173044fb948aeacb4b5ff5c2e8ed41e7b23270c627c6ab96574207731b351496af7ec45f54832e535329549569f0cdea4b0e7a313f48
@@ -148,4 +148,8 @@ module Enumerable
148
148
  end
149
149
  acc
150
150
  end
151
+
152
+ def fold_right(*args, &combine)
153
+ reverse.reduce(*args, &combine&.reverse_args)
154
+ end
151
155
  end
@@ -1,3 +1,3 @@
1
1
  module Abstractivator
2
- VERSION = '0.17.0'
2
+ VERSION = '0.18.0'
3
3
  end
@@ -217,4 +217,22 @@ describe Enumerable do
217
217
  expect(result).to eql [g, a, b]
218
218
  end
219
219
  end
220
+
221
+ describe '#fold_right' do
222
+ it 'folds right' do
223
+ op = proc { |char, acc| "#{char}(#{acc})" }
224
+ expect(%w[].fold_right('z', &op)).to eql 'z'
225
+ expect(%w[a].fold_right('z', &op)).to eql 'a(z)'
226
+ expect(%w[a b].fold_right('z', &op)).to eql 'a(b(z))'
227
+ expect(%w[a b c].fold_right('z', &op)).to eql 'a(b(c(z)))'
228
+ end
229
+ it 'allows the same argument variations as Enumerable#reduce' do
230
+ expect([].fold_right(:+)).to be_nil
231
+ expect([].fold_right(0, :+)).to eql 0
232
+ expect([1].fold_right(:+)).to eql 1
233
+ expect([1].fold_right(0, :+)).to eql 1
234
+ expect([1,2].fold_right(:+)).to eql 3
235
+ expect([1,2].fold_right(0, :+)).to eql 3
236
+ end
237
+ end
220
238
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abstractivator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Winton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-30 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler