monadt 0.1.1 → 0.1.2

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: 4277be1ebc2c809bce2b0d6db287229852bd17de
4
- data.tar.gz: ae2ab51f492de99a09e4375753c9b3c623c96f50
3
+ metadata.gz: a11eed822647903a69b40b4f8bcd3e63bf05dabc
4
+ data.tar.gz: bf5a354e4fb2a4da445b14ad66ed336f5a54d5e9
5
5
  SHA512:
6
- metadata.gz: a4dbfc6e221f47b26b4ef2c38f671bdab6f2d657ecef37a7bd5ad37e00183ec8f5fe4b9073929be39ec28d9ee027dd8610c45bf8afde7285ee5765cedc731d77
7
- data.tar.gz: 6bd0dc62338a9207936698fba178f5859225667f40764ecfd34ab75cf2316023e63d3c57839ad24d99cb801c24806231ed15957a43de8fdc53312a2e3e47c9e1
6
+ metadata.gz: 6560a66faa59564d31ae3f25fe308c5a5ecf4c0458055aa2aaa959ba5632395cc8f32e73cd6173b92e203401bfe5e85ae38fc633aef64ba1b76d3128e73707e0
7
+ data.tar.gz: a54f2e9aeee439626ecd68b30f4a63209fd5cf3950a43dc83730f024392f4eb2c36c95d5443fbf85668deb6e21ebe7b1a994b6d82dd3338cbad7e565ffef753b
@@ -0,0 +1,44 @@
1
+ require 'fiber'
2
+
3
+ module Monadt
4
+ module Enum
5
+ class MonadObj
6
+ def initialize(klass, yielder)
7
+ @klass = klass
8
+ @yielder = yielder
9
+ end
10
+
11
+ def return(val)
12
+ @klass.return val
13
+ end
14
+
15
+ def bind(val)
16
+ @yielder.yield val
17
+ end
18
+ end
19
+ end
20
+
21
+ class DoMEnumerator
22
+ class << self
23
+ def do_m(klass, &blk)
24
+ e = Enumerator.new do |y|
25
+ m_obj = Enum::MonadObj.new klass, y
26
+ blk.call(m_obj)
27
+ end
28
+ do_m_recur(klass, e)
29
+ end
30
+
31
+ def do_m_recur(klass, e)
32
+ begin
33
+ ma = e.next
34
+ rescue StopIteration => ex
35
+ return ex.result
36
+ end
37
+ klass.bind(ma) do |a|
38
+ e.feed a
39
+ do_m_recur(klass, e)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,42 @@
1
+ require 'fiber'
2
+
3
+ module Monadt
4
+ module Fibr
5
+ class MonadObj
6
+ def initialize(klass)
7
+ @klass = klass
8
+ end
9
+
10
+ def return(val)
11
+ @klass.return val
12
+ end
13
+
14
+ def bind(val)
15
+ Fiber.yield val
16
+ end
17
+ end
18
+ end
19
+
20
+ class DoMFiber
21
+ class << self
22
+ def do_m(klass, &blk)
23
+ f = Fiber.new do |y|
24
+ m_obj = Fibr::MonadObj.new klass
25
+ blk.call(m_obj)
26
+ end
27
+ do_m_recur(klass, f, nil)
28
+ end
29
+
30
+ def do_m_recur(klass, f, ma, *args)
31
+ if f.alive?
32
+ ma = f.resume(*args)
33
+ klass.bind(ma) do |a|
34
+ do_m_recur(klass, f, ma, a)
35
+ end
36
+ else
37
+ ma
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monadt
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
  - Will Pleasant-Ryan
@@ -22,6 +22,8 @@ files:
22
22
  - lib/monadt/async.rb
23
23
  - lib/monadt/async_either.rb
24
24
  - lib/monadt/do_m.rb
25
+ - lib/monadt/do_m/enumerator.rb
26
+ - lib/monadt/do_m/fiber.rb
25
27
  - lib/monadt/either.rb
26
28
  - lib/monadt/list.rb
27
29
  - lib/monadt/maybe.rb