t_algebra 0.1.1 → 0.1.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
  SHA256:
3
- metadata.gz: 47c013dcdeaf282791c7043884001899230c9d47bd4e33b27b25654982bd59e1
4
- data.tar.gz: 3d063906d1a462276f0a8ab12bb09cfb5ded2b9e6b9630206b5b81966784d750
3
+ metadata.gz: 2c61dbc20ba8e3f3b37778601949560237c224902454ab26b935c5dc048c8511
4
+ data.tar.gz: 1a9f3e3b7dc17c500c7e827514cc332b1ac9d4c5da919d8de9c4cd16cb1fc6a8
5
5
  SHA512:
6
- metadata.gz: b16ffc8e653ff03cc6128863943c41367be132d4218041a9e636ce74495e7657a6468146449c12661d1dc4f66be2e2ac6e3342e31bb6677a20b36a267d44cc4d
7
- data.tar.gz: 7070554503dcec80113967176aa703481989aa716d8758f28bb07ae8b1e7e5a42acd94f84a399e7ad393d53c2526f61a0f1cb5f8ec2121864674d2f80fdd90a3
6
+ metadata.gz: 823c7c82e469fb68b44cb00dda7f796ce1d8c1717c9cb312e659d42a68d21a46b43c34b8af08792728fb13042302138b212c9ec93d1ccf1b338ba13036c6afb8
7
+ data.tar.gz: 0b6223275fa9dc3b21e31ad1a0975457e3214351aa4b008cd1e894ef51bd2fca60e60159a42f9c55f9d5ce49da8fd487502b7d4ce3991891ba6c452e6ecf5899
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- t_algebra (0.1.0)
4
+ t_algebra (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -26,6 +26,12 @@ module TAlgebra
26
26
  parser = parse(o.respond_to?(:[]) ? o[key] : o.send(key))
27
27
  parser.with_name(key).required
28
28
  end
29
+
30
+ def run_bind(ma, &block)
31
+ raise "Yield blocks must return instances of #{self}. Got #{ma.class}" unless [Parser, Parser::Optional].include?(ma.class)
32
+
33
+ ma.as_parser.bind(&block)
34
+ end
29
35
  end
30
36
 
31
37
  attr_reader :name
@@ -91,6 +97,10 @@ module TAlgebra
91
97
  end
92
98
  end
93
99
 
100
+ def as_parser
101
+ instance_of?(Parser::Optional) ? Parser.new(is: is, value: value, name: name) : self
102
+ end
103
+
94
104
  private
95
105
 
96
106
  def dup
@@ -21,6 +21,11 @@ module TAlgebra
21
21
  run_recursive(e, [])
22
22
  end
23
23
 
24
+ def run_bind(ma)
25
+ raise "Yield blocks must return instances of #{self}" unless ma.instance_of?(self)
26
+ ma.bind
27
+ end
28
+
24
29
  def lift_a2(ma, mb, &block)
25
30
  ma.bind do |a|
26
31
  mb.bind do |b|
@@ -42,7 +47,7 @@ module TAlgebra
42
47
  if is_complete(enum)
43
48
  pure(value(enum))
44
49
  else
45
- enum.next.call.bind do |a|
50
+ run_bind(enum.next.call) do |a|
46
51
  run_recursive(enum, historical_values + [a])
47
52
  end
48
53
  end
@@ -1,3 +1,3 @@
1
1
  module TAlgebra
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: t_algebra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - aaron