kleisli-run 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/kleisli/run/version.rb +1 -1
- data/lib/kleisli/run.rb +15 -8
- data/test/kleisli/run_test.rb +0 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWU4ODZmODNhMmU3MWI2OWZmYmExMWU5NzM1YzlmMGMzMThmY2Y1Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTY4ZGY5OTRhYjQ3OGRhYTNiN2MxMzRiZDE4ZjIyOWY4ODY2ZmEyOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2U1Mzc4ZTQ4NTIzODRhOGMyNDgyYWMxYThlMzg4YWNmMTVkZmMxNjg5Y2Uy
|
10
|
+
ZWVhYmYzMzhiMjllMGM2OTljYTc2OWIzYTVhOTgzMzNmODhhYmMwNjM0ZTEw
|
11
|
+
NTQ2NDYyYjVmNzI4MTAzZjNiMTk0ZDQxNjhiNWVmZDc0NDEzMjA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzJhNTMwNmRkYzMxMDVlYTU5YmI0NzFhNjkzNmVlYWY4OGEyNDk1NGUwNmYw
|
14
|
+
ZDY1YmUxZTNlOWRkMDU2YmE0ZTA2MWIyNDNjYWQ1OWRjMmQ4NGY1ODY1YmE4
|
15
|
+
YTQ2MjIxNTU5NTZjYjA4MGIyYWE1NjcyMzUyZThjMmRjYzQwZTY=
|
data/lib/kleisli/run/version.rb
CHANGED
data/lib/kleisli/run.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require "kleisli/run/version"
|
2
|
-
require 'ostruct'
|
3
2
|
|
4
3
|
module Kleisli
|
5
4
|
|
6
|
-
def self.run(&block)
|
7
|
-
r =
|
5
|
+
def self.run(runner_impl = Runner, &block)
|
6
|
+
r = runner_impl.new(block.binding)
|
8
7
|
begin
|
9
8
|
res = r.instance_eval(&block)
|
10
9
|
r.start.fmap { res }
|
@@ -17,7 +16,7 @@ module Kleisli
|
|
17
16
|
attr_reader :start
|
18
17
|
|
19
18
|
def initialize(block_binding)
|
20
|
-
@
|
19
|
+
@hash = {}
|
21
20
|
@stopped = false
|
22
21
|
@start = false
|
23
22
|
@o_self = block_binding.eval('self')
|
@@ -26,9 +25,17 @@ module Kleisli
|
|
26
25
|
def extract(val, m)
|
27
26
|
called = false
|
28
27
|
@start = m unless @start
|
29
|
-
m >-> i { called = true;
|
28
|
+
m >-> i { called = true; set_value(val, i) }
|
30
29
|
raise MonadTerminator.new(m) unless called
|
31
|
-
|
30
|
+
get_value(val)
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_value(k, v)
|
34
|
+
@hash[k] = v
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_value(k)
|
38
|
+
@hash[k]
|
32
39
|
end
|
33
40
|
|
34
41
|
def method_missing(m, *args)
|
@@ -39,9 +46,9 @@ module Kleisli
|
|
39
46
|
return extract(m, args.first[:from])
|
40
47
|
end
|
41
48
|
if args.empty?
|
42
|
-
|
49
|
+
get_value(m)
|
43
50
|
else
|
44
|
-
|
51
|
+
set_value(m, args.first)
|
45
52
|
end
|
46
53
|
end
|
47
54
|
end
|
data/test/kleisli/run_test.rb
CHANGED