monadt 0.1.0 → 0.1.1

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: 7746a87e5355708be40ab3440bb65ea902e9add0
4
- data.tar.gz: 6baed7771d0bb368794f0314d26bc18f8f51d292
3
+ metadata.gz: 4277be1ebc2c809bce2b0d6db287229852bd17de
4
+ data.tar.gz: ae2ab51f492de99a09e4375753c9b3c623c96f50
5
5
  SHA512:
6
- metadata.gz: 61d461c44b602499a075876e5883731553f173db40ef3a267dcc099c1061ab6a3bc399a169ba8763df39ba7d1e266b7f6fc9c1f5df74f47d436709084fbfba67
7
- data.tar.gz: fd8712a4f9092c683b906ab02908afae83ef4497f9bfbb5f3e5c82a8ad9a65c25155a3e76c2dd300fa3b5c3a9c0994bae501bb67a310c3346fdfea06e5f90d02
6
+ metadata.gz: a4dbfc6e221f47b26b4ef2c38f671bdab6f2d657ecef37a7bd5ad37e00183ec8f5fe4b9073929be39ec28d9ee027dd8610c45bf8afde7285ee5765cedc731d77
7
+ data.tar.gz: 6bd0dc62338a9207936698fba178f5859225667f40764ecfd34ab75cf2316023e63d3c57839ad24d99cb801c24806231ed15957a43de8fdc53312a2e3e47c9e1
@@ -0,0 +1,22 @@
1
+ require_relative 'do_m/fiber'
2
+ require_relative 'do_m/enumerator'
3
+
4
+ module Monadt
5
+ class Monad
6
+
7
+ class << self
8
+ def engine
9
+ if ENV['DO_M_ENGINE'].nil?
10
+ DoMFiber
11
+ else
12
+ Object.const_get(ENV['DO_M_ENGINE'])
13
+ end
14
+ end
15
+
16
+ def do_m(klass, &blk)
17
+ engine.do_m(klass, &blk)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
data/lib/monadt.rb CHANGED
@@ -4,7 +4,7 @@ require 'monadt/async'
4
4
  require 'monadt/state'
5
5
  require 'monadt/async_either'
6
6
  require 'monadt/reader_state_either'
7
- require 'monadt/monad'
7
+ require 'monadt/do_m'
8
8
 
9
9
  module Monadt
10
10
  class Monad
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Pleasant-Ryan
@@ -21,10 +21,10 @@ files:
21
21
  - lib/monadt/adt.rb
22
22
  - lib/monadt/async.rb
23
23
  - lib/monadt/async_either.rb
24
+ - lib/monadt/do_m.rb
24
25
  - lib/monadt/either.rb
25
26
  - lib/monadt/list.rb
26
27
  - lib/monadt/maybe.rb
27
- - lib/monadt/monad.rb
28
28
  - lib/monadt/reader.rb
29
29
  - lib/monadt/reader_state_either.rb
30
30
  - lib/monadt/state.rb
data/lib/monadt/monad.rb DELETED
@@ -1,82 +0,0 @@
1
- require 'fiber'
2
-
3
- module Monadt
4
- module Internal
5
- class MonadObjFiber
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
-
19
- class MonadObjEnum
20
- def initialize(klass, yielder)
21
- @klass = klass
22
- @yielder = yielder
23
- end
24
-
25
- def return(val)
26
- @klass.return val
27
- end
28
-
29
- def bind(val)
30
- @yielder.yield val
31
- end
32
- end
33
- end
34
-
35
- class Monad
36
- class << self
37
- def do_m(klass, &blk)
38
- do_m_fiber(klass, &blk)
39
- end
40
-
41
- def do_m_fiber(klass, &blk)
42
- f = Fiber.new do |y|
43
- m_obj = Internal::MonadObjFiber.new klass
44
- blk.call(m_obj)
45
- end
46
- do_m_recur_fiber(klass, f, nil)
47
- end
48
-
49
- def do_m_recur_fiber(klass, f, ma, *args)
50
- if f.alive?
51
- ma = f.resume(*args)
52
- klass.bind(ma) do |a|
53
- do_m_recur_fiber(klass, f, ma, a)
54
- end
55
- else
56
- ma
57
- end
58
- end
59
-
60
- def do_m_enum(klass, &blk)
61
- e = Enumerator.new do |y|
62
- m_obj = Internal::MonadObjEnum.new klass, y
63
- blk.call(m_obj)
64
- end
65
- do_m_recur_enum(klass, e)
66
- end
67
-
68
- def do_m_recur_enum(klass, e)
69
- begin
70
- ma = e.next
71
- rescue StopIteration => ex
72
- return ex.result
73
- end
74
- klass.bind(ma) do |a|
75
- e.feed a
76
- do_m_recur_enum(klass, e)
77
- end
78
- end
79
- end
80
- end
81
- end
82
-