abstractivator 0.0.24 → 0.0.25

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: e68abf828440fc78dcde5dcfd7ffbdfb97d12947
4
- data.tar.gz: 36c75eb045436c4af77795747cec641e8aaf3b3d
3
+ metadata.gz: 0c7615cf2a1920441356f004c04e538266bcff8a
4
+ data.tar.gz: 3cbafbd8d4d96004a3bb71ad866559f84efc482e
5
5
  SHA512:
6
- metadata.gz: 6253948262fb4db237c054869d8cf198a39d3abc0d9ba8115ce9ef56c6c06b7322d416604782d8ddd7398b07394b7fd16fb377b8bc477903a2c9770c2fe13be5
7
- data.tar.gz: f367bfbca002208c663a7d96decec94a3f010f56b731c760f9ac6f2b79ed45c13c1caaa00ccc6564884637783476df96c44ba1015dcd685952b661e95f4672af
6
+ metadata.gz: 505a6935ad5889bcb7cfdfac6fb95cf16a043e08723f48bd21eac5a3a43274f4b99474bc054b177a45c9a8e55cea551ed49f720dacf9f8ab5343ff6999bd053b
7
+ data.tar.gz: 71b33fcc5c8399291aa465943cbbd112958c5b9a6db041c7f21148f2dacedd507132db0fc23614ea5f70214e75e99f6cf95eed06323fe3c66b61426dcb23606a
@@ -25,6 +25,20 @@ class Proc
25
25
  procs.map(&:to_proc).inject_right(identity) { |inner, p| p.compose(inner) }
26
26
  end
27
27
 
28
+ # composes procedures in reverse order.
29
+ # useful for applying a series of transformations.
30
+ # pipe(f, g, h) returns the procedure
31
+ # proc { |x| h.call(g.call(f.call(x))) }
32
+ def self.pipe(*procs)
33
+ Proc.compose(*procs.reverse)
34
+ end
35
+
36
+ # makes a pipeline transform as with Proc::pipe
37
+ # and applies it to the given value.
38
+ def self.pipe_value(value, *procs)
39
+ Proc.pipe(*procs).call(value)
40
+ end
41
+
28
42
  # returns the identity function
29
43
  def self.identity
30
44
  proc {|x| x}
@@ -1,3 +1,3 @@
1
1
  module Abstractivator
2
- VERSION = '0.0.24'
2
+ VERSION = '0.0.25'
3
3
  end
@@ -25,6 +25,25 @@ context 'in the world of functional programming' do
25
25
  end
26
26
  end
27
27
 
28
+ describe 'Proc::pipe' do
29
+ it 'composes procs in reverse order' do
30
+ expect(Proc.pipe.call(3)).to eql 3
31
+ expect(Proc.pipe(double).call(3)).to eql 6
32
+ expect(Proc.pipe(double, square).call(3)).to eql 36
33
+ expect(Proc.pipe(double, square, negate).call(3)).to eql -36
34
+ end
35
+ it 'coerces the args to a proc with to_proc' do
36
+ p = Proc.pipe(:first, :abs)
37
+ expect(p.call([-5, 6])).to eql 5
38
+ end
39
+ end
40
+
41
+ describe 'Proc::pipe_value' do
42
+ it 'makes a Proc::pipe pipeline and applies it to a value' do
43
+ expect(Proc.pipe_value(3, double, square, negate)).to eql -36
44
+ end
45
+ end
46
+
28
47
  describe 'Proc#reverse_args' do
29
48
  it 'reverse argument order' do
30
49
  divide = proc {|a, b| a / b}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abstractivator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Winton