arrows 0.0.1 → 0.0.2

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3959c84c04b961af219c9ebace94e96b8dee661e
4
- data.tar.gz: 1f8938d020276560369e30f791a8ec7607c9e267
3
+ metadata.gz: 1b8e5f6e4eb4a43c2f35518b07bf4b9f0a8a48f4
4
+ data.tar.gz: b28cecf3536eba6249380a4b1b95ccebe70f31c1
5
5
  SHA512:
6
- metadata.gz: c1c511982b5353cce121f0d99783d04a93a7760dfcad30b2e50308c4dba5edf94b52d27928a5a9d0b2c96363c246cce7e552a13ec4ca3b5e7189d940576e6589
7
- data.tar.gz: 6d56bc8cbce8fa1d48ff1ab14a0cdcdf3195f952b28f6147941e9b0cb520c34dd2611362a18f04bd0a9d2438037231724d3d5dab8f12f4ad5fe1e235284e6bd1
6
+ metadata.gz: dca8f5f4ff089919b40f3aad4ea9bc074c54be226dd39cefd4f52376a9dcb85946472cce5cbd2b04a39904adaf7f91759967c13fdb9708ab49958df18e2f70f2
7
+ data.tar.gz: 4da8524c8d276ee903bdc14176733ad99b9157ec2621b59fd35d5b984140b0e56badfb292633793aa29e7b9feb550dc263f45635a97d419365ccad96f4eb0e72
data/README.md CHANGED
@@ -7,6 +7,7 @@ actually useful set of functional tools for day-to-day Ruby programming
7
7
 
8
8
  Features:
9
9
 
10
+ *note, see spec/arrows/proc_spec.rb to get an idea how to use this junk
10
11
  ### Function composition
11
12
 
12
13
  If given
@@ -17,6 +18,7 @@ x -> H -> z
17
18
 
18
19
  As in we pipe what F poops out into the mouth of G a la Human Centipede
19
20
 
21
+
20
22
  ### Applicative composition
21
23
  Calls map (in Haskell, they generalize it to fmap) on the data passed in
22
24
 
@@ -2,6 +2,11 @@ require "arrows/version"
2
2
 
3
3
  module Arrows
4
4
  class << self
5
+ def concurrent(f,g)
6
+ Arrows::Proc.new do |*args|
7
+ [f[*args.first], g[*args.last]]
8
+ end
9
+ end
5
10
  def fanout(f,g)
6
11
  Arrows::Proc.new { |*args| [f[*args], g[*args]] }
7
12
  end
@@ -23,7 +28,9 @@ module Arrows
23
28
  x.respond_to?(:call) && x.respond_to?(:arity)
24
29
  end
25
30
  def wrap_proc(f)
26
- Arrows::Proc.new { |*args| f[*args] }
31
+ Arrows::Proc.new do |*args|
32
+ f[*args]
33
+ end
27
34
  end
28
35
  end
29
36
  class Proc < ::Proc
@@ -41,5 +48,10 @@ module Arrows
41
48
  def /(f)
42
49
  Arrows.fanout self, Arrows.lift(f)
43
50
  end
51
+
52
+ # concurrent composition
53
+ def %(f)
54
+ Arrows.concurrent self, Arrows.lift(f)
55
+ end
44
56
  end
45
57
  end
@@ -1,3 +1,3 @@
1
1
  module Arrows
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -19,7 +19,7 @@ RSpec.describe Arrows::Proc do
19
19
  specify { should eq [10, 12, 14] }
20
20
  end
21
21
 
22
- context '+ fanout' do
22
+ context '/ fanout' do
23
23
  let(:times2) { Arrows.lift -> (x) { x * 2 } }
24
24
  let(:plus3) { Arrows.lift -> (x) { x + 3 } }
25
25
  let(:four) { Arrows.lift 4 }
@@ -27,4 +27,52 @@ RSpec.describe Arrows::Proc do
27
27
  subject { six_eight.call }
28
28
  specify { should eq [8, 7] }
29
29
  end
30
+
31
+ context '% concurrent' do
32
+ let(:times2) { Arrows.lift -> (x) { x * 2 } }
33
+ let(:plus3) { Arrows.lift -> (x) { x + 3 } }
34
+ let(:four) { Arrows.lift [4,6] }
35
+ context 'validity' do
36
+ subject { times2.call 2 }
37
+ specify { should eq 4 }
38
+ end
39
+ context 'arity' do
40
+ let(:par) { times2 % plus3 }
41
+ subject { par.call 1,2 }
42
+ specify { should eq [2, 5] }
43
+ end
44
+ context 'result' do
45
+ let(:eight_nine) { four >> times2 % plus3 }
46
+ subject { eight_nine.call }
47
+ specify { should eq [8,9] }
48
+ end
49
+ end
50
+
51
+ context '%/ fanout into concurrent' do
52
+ let(:add1) { Arrows.lift -> (x) { x + 1 } }
53
+ let(:add4) { Arrows.lift -> (x) { x + 4 } }
54
+ let(:two) { Arrows.lift 2 }
55
+ let(:result) { two >> add1 / add4 >> add1 % add4 }
56
+ context 'result' do
57
+ subject { result.call }
58
+ specify { should eq [4, 10] }
59
+ end
60
+ end
61
+
62
+ context '>=%/ applicative fanout into concurrent' do
63
+ let(:add1) { Arrows.lift -> (x) { x + 1 } }
64
+ let(:add4) { Arrows.lift -> (x) { x + 4 } }
65
+ let(:twos) { Arrows.lift [2,2,2] }
66
+ let(:transform) { add1 / add4 >> add1 % add4 }
67
+ let(:result) { twos >= add1 / add4 >> add1 % add4 }
68
+ context 'result' do
69
+ subject { result.call }
70
+ specify { should eq [[4,10], [4,10], [4,10]] }
71
+ end
72
+ context 'similarity' do
73
+ let(:actual) { twos >= transform }
74
+ subject { result.call }
75
+ specify { should eq actual.call }
76
+ end
77
+ end
30
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arrows
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-04 00:00:00.000000000 Z
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler