tiny_frp 1.0.0 → 1.1.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: 95461bc9e9bcaec52bd9d693befbab7f761c4596
4
- data.tar.gz: 864a0e822365a039c315192d02c509b8a15ddeef
3
+ metadata.gz: e66f1f682e89029ca27be8be4a1333ce0e11704f
4
+ data.tar.gz: 8606a26d57699ae70a6146acb90dbd1d7a127bc6
5
5
  SHA512:
6
- metadata.gz: 68ee1322327823da24345bbd919030bec4e33990d2379612c1d3efa09d982215c73c39d4171489edda8786a90aa22a4c29334e64e7220fbdd9b47fbf6e64e719
7
- data.tar.gz: 34f5f5cdd816f06c61a22a07ff5625d24b43370a0784e48127d4b281bef255cebb18dceb478e1e66f41f611508ed2a8586145921632e772e0a16402b4e241344
6
+ metadata.gz: a38f4eebfcd858c6455c438c624be6a3fb7a9bfb52362afe8dbe8b38b690142114a4ea12e782440d47c1076938052b2625bfbe8e11caa923fe68a8a39a3b7b4c
7
+ data.tar.gz: e52ec854b28ff66e4b27da0df75c2fca5253780c0037ec9c9b9af5cfa677431909cd70c8fdef215749e5635968c010184c5a8da0d3e5997ee636048e2d3c2b87
data/README.md CHANGED
@@ -7,7 +7,7 @@ Very small and simple library to do (functional)-reactive-programming in Ruby.
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'frp'
10
+ gem 'tiny_frp'
11
11
  ```
12
12
 
13
13
  And then execute:
@@ -16,7 +16,7 @@ And then execute:
16
16
 
17
17
  Or install it yourself as:
18
18
 
19
- $ gem install frp
19
+ $ gem install tiny_frp
20
20
 
21
21
  ## Usage
22
22
 
@@ -27,7 +27,33 @@ module TinyFRP
27
27
  end
28
28
 
29
29
  def +(node)
30
- Bundle.new(self, node)
30
+ case [self, node]
31
+ when [Bundle, Bundle]
32
+ Bundle.new(*(self.nodes + node.nodes))
33
+ when [Node, Bundle]
34
+ Bundle.new(*([self] + node.nodes))
35
+ when [Bundle, Node]
36
+ Bundle.new(*(self.nodes + [node]))
37
+ else
38
+ Bundle.new(self, node)
39
+ end
40
+ end
41
+
42
+ def *(node)
43
+ case [self, node]
44
+ when [Split, Split]
45
+ Split.new(*(self.nodes + node.nodes))
46
+ when [Node, Split]
47
+ Split.new(*([self] + node.nodes))
48
+ when [Split, Node]
49
+ Split.new(*(self.nodes + [node]))
50
+ else
51
+ Split.new(self, node)
52
+ end
53
+ end
54
+
55
+ def **(integer)
56
+ Split.new(*integer.times.map{self})
31
57
  end
32
58
 
33
59
  def call(memo, last_memo, *args)
@@ -53,6 +79,12 @@ module TinyFRP
53
79
  end
54
80
  end
55
81
 
82
+ class Lifta < Lift
83
+ def calc(memo, last_memo, *args)
84
+ memo.merge(self => @proc.call(*args))
85
+ end
86
+ end
87
+
56
88
  class Foldp < Node
57
89
  def initialize(initial_state, &proc)
58
90
  @initial_state, @proc = initial_state, proc
@@ -100,6 +132,8 @@ module TinyFRP
100
132
  end
101
133
 
102
134
  class Bundle < Node
135
+ attr_reader :nodes
136
+
103
137
  def initialize(*nodes)
104
138
  @nodes = nodes
105
139
  end
@@ -118,4 +152,21 @@ module TinyFRP
118
152
  res.merge(self => @nodes.inject([]){|acc, n| acc + res[n]})
119
153
  end
120
154
  end
155
+
156
+ class Split < Node
157
+ attr_reader :nodes
158
+
159
+ def initialize(*nodes)
160
+ @nodes = nodes
161
+ end
162
+
163
+ def argc
164
+ @argc ||= @nodes.first.argc
165
+ end
166
+
167
+ def calc(memo, last_memo, *args)
168
+ res = @nodes.inject(memo){|acc, n| n.call(acc, last_memo, *args)}
169
+ res.merge(self => @nodes.inject([]){|acc, n| acc + res[n]})
170
+ end
171
+ end
121
172
  end
@@ -1,3 +1,3 @@
1
1
  module TinyFRP
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -13,6 +13,10 @@ module TinyFRP
13
13
  def foldp(init_state, &proc)
14
14
  TinyFRP::Foldp.new(init_state, &proc)
15
15
  end
16
+
17
+ def lifta(&proc)
18
+ TinyFRP::Lifta.new(&proc)
19
+ end
16
20
  end
17
21
 
18
22
  class TinyFRPTest < Test::Unit::TestCase
@@ -40,6 +44,17 @@ module TinyFRP
40
44
  node = foldp(0){|a| a + 1} + foldp(1){|a| a + 1} + foldp(2){|a| a + 1}
41
45
  assert_equal([[1, 2, 3], [2, 3, 4], [3, 4, 5]], TinyFRP.process(node, 3))
42
46
  end
47
+
48
+ def test_split
49
+ node = foldp(0){|a| a + 1} >> lift{|a| a - 1} * lift{|a| a + 1}
50
+ assert_equal([[0, 2], [1, 3], [2, 4]], TinyFRP.process(node, 3))
51
+ end
52
+
53
+ def test_lifta
54
+ inp = lift{0} + lift{1}
55
+ node = lifta{|a, b| [a, b]} << inp
56
+ assert_equal([[0, 1], [0, 1], [0, 1]], TinyFRP.process(node, 3))
57
+ end
43
58
  end
44
59
  end
45
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_frp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawaken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler