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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/t_algebra/monad/parser.rb +10 -0
- data/lib/t_algebra/monad.rb +6 -1
- data/lib/t_algebra/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c61dbc20ba8e3f3b37778601949560237c224902454ab26b935c5dc048c8511
|
4
|
+
data.tar.gz: 1a9f3e3b7dc17c500c7e827514cc332b1ac9d4c5da919d8de9c4cd16cb1fc6a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 823c7c82e469fb68b44cb00dda7f796ce1d8c1717c9cb312e659d42a68d21a46b43c34b8af08792728fb13042302138b212c9ec93d1ccf1b338ba13036c6afb8
|
7
|
+
data.tar.gz: 0b6223275fa9dc3b21e31ad1a0975457e3214351aa4b008cd1e894ef51bd2fca60e60159a42f9c55f9d5ce49da8fd487502b7d4ce3991891ba6c452e6ecf5899
|
data/Gemfile.lock
CHANGED
@@ -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
|
data/lib/t_algebra/monad.rb
CHANGED
@@ -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
|
50
|
+
run_bind(enum.next.call) do |a|
|
46
51
|
run_recursive(enum, historical_values + [a])
|
47
52
|
end
|
48
53
|
end
|
data/lib/t_algebra/version.rb
CHANGED