ruff 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +366 -0
- data/.solargraph.yml +18 -0
- data/Gemfile +6 -2
- data/Gemfile.lock +39 -1
- data/Rakefile +22 -22
- data/docs/Ruff/Effect.html +14 -14
- data/docs/Ruff/Handler.html +24 -32
- data/docs/Ruff/Standard/CurrentTime/Instance.html +15 -15
- data/docs/Ruff/Standard/CurrentTime.html +10 -10
- data/docs/Ruff/Standard/Defer/Instance.html +20 -24
- data/docs/Ruff/Standard/Defer.html +3 -3
- data/docs/Ruff/Standard/State/Instance.html +37 -37
- data/docs/Ruff/Standard/State.html +25 -25
- data/docs/Ruff/Standard.html +1 -1
- data/docs/Ruff/Throws/Eff.html +13 -13
- data/docs/Ruff/Throws/Resend.html +13 -13
- data/docs/Ruff/Throws.html +1 -1
- data/docs/Ruff.html +13 -24
- data/docs/_index.html +1 -1
- data/docs/file.README.html +1 -1
- data/docs/index.html +1 -1
- data/docs/top-level-namespace.html +1 -1
- data/lib/ruff/effect.rb +3 -1
- data/lib/ruff/handler.rb +21 -24
- data/lib/ruff/objects.rb +3 -1
- data/lib/ruff/standard/current_time.rb +5 -4
- data/lib/ruff/standard/defer.rb +14 -14
- data/lib/ruff/standard/state.rb +18 -17
- data/lib/ruff/standard.rb +5 -4
- data/lib/ruff/version.gen.sh +7 -0
- data/lib/ruff/version.rb +3 -1
- data/lib/ruff.rb +6 -4
- data/ruff.gemspec +17 -17
- data/version +1 -0
- metadata +6 -3
- data/lib/ruff/version.cpp.rb +0 -5
- data/version.h +0 -1
@@ -242,12 +242,12 @@
|
|
242
242
|
<pre class="lines">
|
243
243
|
|
244
244
|
|
245
|
-
|
246
|
-
|
247
|
-
|
245
|
+
44
|
246
|
+
45
|
247
|
+
46</pre>
|
248
248
|
</td>
|
249
249
|
<td>
|
250
|
-
<pre class="code"><span class="info file"># File 'lib/ruff/standard/state.rb', line
|
250
|
+
<pre class="code"><span class="info file"># File 'lib/ruff/standard/state.rb', line 44</span>
|
251
251
|
|
252
252
|
<span class='kw'>def</span> <span class='id identifier rubyid_get'>get</span>
|
253
253
|
<span class='ivar'>@inst</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span>
|
@@ -272,14 +272,14 @@
|
|
272
272
|
<pre class="lines">
|
273
273
|
|
274
274
|
|
275
|
-
|
276
|
-
|
277
|
-
|
275
|
+
48
|
276
|
+
49
|
277
|
+
50</pre>
|
278
278
|
</td>
|
279
279
|
<td>
|
280
|
-
<pre class="code"><span class="info file"># File 'lib/ruff/standard/state.rb', line
|
280
|
+
<pre class="code"><span class="info file"># File 'lib/ruff/standard/state.rb', line 48</span>
|
281
281
|
|
282
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_modify'>modify</span>
|
282
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_modify'>modify</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_fn'>fn</span><span class='rparen'>)</span>
|
283
283
|
<span class='ivar'>@inst</span><span class='period'>.</span><span class='id identifier rubyid_modify'>modify</span> <span class='op'>&</span><span class='id identifier rubyid_fn'>fn</span>
|
284
284
|
<span class='kw'>end</span></pre>
|
285
285
|
</td>
|
@@ -302,14 +302,14 @@
|
|
302
302
|
<pre class="lines">
|
303
303
|
|
304
304
|
|
305
|
-
|
306
|
-
|
307
|
-
|
305
|
+
52
|
306
|
+
53
|
307
|
+
54</pre>
|
308
308
|
</td>
|
309
309
|
<td>
|
310
|
-
<pre class="code"><span class="info file"># File 'lib/ruff/standard/state.rb', line
|
310
|
+
<pre class="code"><span class="info file"># File 'lib/ruff/standard/state.rb', line 52</span>
|
311
311
|
|
312
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_put'>put</span>
|
312
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_put'>put</span><span class='lparen'>(</span><span class='id identifier rubyid_s'>s</span><span class='rparen'>)</span>
|
313
313
|
<span class='ivar'>@inst</span><span class='period'>.</span><span class='id identifier rubyid_put'>put</span> <span class='id identifier rubyid_s'>s</span>
|
314
314
|
<span class='kw'>end</span></pre>
|
315
315
|
</td>
|
@@ -332,14 +332,14 @@
|
|
332
332
|
<pre class="lines">
|
333
333
|
|
334
334
|
|
335
|
-
|
336
|
-
|
337
|
-
|
335
|
+
60
|
336
|
+
61
|
337
|
+
62</pre>
|
338
338
|
</td>
|
339
339
|
<td>
|
340
|
-
<pre class="code"><span class="info file"># File 'lib/ruff/standard/state.rb', line
|
340
|
+
<pre class="code"><span class="info file"># File 'lib/ruff/standard/state.rb', line 60</span>
|
341
341
|
|
342
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_with'>with</span>
|
342
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_task'>task</span><span class='rparen'>)</span>
|
343
343
|
<span class='ivar'>@inst</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span> <span class='op'>&</span><span class='id identifier rubyid_task'>task</span>
|
344
344
|
<span class='kw'>end</span></pre>
|
345
345
|
</td>
|
@@ -362,14 +362,14 @@
|
|
362
362
|
<pre class="lines">
|
363
363
|
|
364
364
|
|
365
|
-
|
366
|
-
|
367
|
-
|
365
|
+
56
|
366
|
+
57
|
367
|
+
58</pre>
|
368
368
|
</td>
|
369
369
|
<td>
|
370
|
-
<pre class="code"><span class="info file"># File 'lib/ruff/standard/state.rb', line
|
370
|
+
<pre class="code"><span class="info file"># File 'lib/ruff/standard/state.rb', line 56</span>
|
371
371
|
|
372
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_with_init'>with_init</span>
|
372
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_with_init'>with_init</span><span class='lparen'>(</span><span class='id identifier rubyid_init'>init</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_task'>task</span><span class='rparen'>)</span>
|
373
373
|
<span class='ivar'>@inst</span><span class='period'>.</span><span class='id identifier rubyid_with_init'>with_init</span> <span class='id identifier rubyid_init'>init</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_task'>task</span>
|
374
374
|
<span class='kw'>end</span></pre>
|
375
375
|
</td>
|
@@ -382,7 +382,7 @@
|
|
382
382
|
</div>
|
383
383
|
|
384
384
|
<div id="footer">
|
385
|
-
Generated on Thu Oct 3
|
385
|
+
Generated on Thu Oct 3 05:05:04 2019 by
|
386
386
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
387
387
|
0.9.20 (ruby-2.6.4).
|
388
388
|
</div>
|
data/docs/Ruff/Standard.html
CHANGED
@@ -105,7 +105,7 @@
|
|
105
105
|
</div>
|
106
106
|
|
107
107
|
<div id="footer">
|
108
|
-
Generated on Thu Oct 3
|
108
|
+
Generated on Thu Oct 3 05:05:04 2019 by
|
109
109
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
110
110
|
0.9.20 (ruby-2.6.4).
|
111
111
|
</div>
|
data/docs/Ruff/Throws/Eff.html
CHANGED
@@ -243,12 +243,12 @@
|
|
243
243
|
<pre class="lines">
|
244
244
|
|
245
245
|
|
246
|
-
|
247
|
-
|
248
|
-
|
246
|
+
16
|
247
|
+
17
|
248
|
+
18</pre>
|
249
249
|
</td>
|
250
250
|
<td>
|
251
|
-
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line
|
251
|
+
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line 16</span>
|
252
252
|
|
253
253
|
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_id'>id</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
|
254
254
|
<span class='ivar'>@id</span> <span class='op'>=</span> <span class='id identifier rubyid_id'>id</span><span class='semicolon'>;</span> <span class='ivar'>@args</span> <span class='op'>=</span> <span class='id identifier rubyid_args'>args</span>
|
@@ -290,12 +290,12 @@
|
|
290
290
|
<pre class="lines">
|
291
291
|
|
292
292
|
|
293
|
-
|
294
|
-
|
295
|
-
|
293
|
+
13
|
294
|
+
14
|
295
|
+
15</pre>
|
296
296
|
</td>
|
297
297
|
<td>
|
298
|
-
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line
|
298
|
+
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line 13</span>
|
299
299
|
|
300
300
|
<span class='kw'>def</span> <span class='id identifier rubyid_args'>args</span>
|
301
301
|
<span class='ivar'>@args</span>
|
@@ -332,12 +332,12 @@
|
|
332
332
|
<pre class="lines">
|
333
333
|
|
334
334
|
|
335
|
-
|
336
|
-
|
337
|
-
|
335
|
+
10
|
336
|
+
11
|
337
|
+
12</pre>
|
338
338
|
</td>
|
339
339
|
<td>
|
340
|
-
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line
|
340
|
+
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line 10</span>
|
341
341
|
|
342
342
|
<span class='kw'>def</span> <span class='id identifier rubyid_id'>id</span>
|
343
343
|
<span class='ivar'>@id</span>
|
@@ -353,7 +353,7 @@
|
|
353
353
|
</div>
|
354
354
|
|
355
355
|
<div id="footer">
|
356
|
-
Generated on Thu Oct 3
|
356
|
+
Generated on Thu Oct 3 05:05:04 2019 by
|
357
357
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
358
358
|
0.9.20 (ruby-2.6.4).
|
359
359
|
</div>
|
@@ -243,12 +243,12 @@
|
|
243
243
|
<pre class="lines">
|
244
244
|
|
245
245
|
|
246
|
-
|
247
|
-
|
248
|
-
|
246
|
+
32
|
247
|
+
33
|
248
|
+
34</pre>
|
249
249
|
</td>
|
250
250
|
<td>
|
251
|
-
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line
|
251
|
+
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line 32</span>
|
252
252
|
|
253
253
|
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_eff'>eff</span><span class='comma'>,</span> <span class='id identifier rubyid_k'>k</span><span class='rparen'>)</span>
|
254
254
|
<span class='ivar'>@eff</span> <span class='op'>=</span> <span class='id identifier rubyid_eff'>eff</span><span class='semicolon'>;</span> <span class='ivar'>@k</span> <span class='op'>=</span> <span class='id identifier rubyid_k'>k</span>
|
@@ -290,12 +290,12 @@
|
|
290
290
|
<pre class="lines">
|
291
291
|
|
292
292
|
|
293
|
-
|
294
|
-
|
295
|
-
|
293
|
+
26
|
294
|
+
27
|
295
|
+
28</pre>
|
296
296
|
</td>
|
297
297
|
<td>
|
298
|
-
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line
|
298
|
+
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line 26</span>
|
299
299
|
|
300
300
|
<span class='kw'>def</span> <span class='id identifier rubyid_eff'>eff</span>
|
301
301
|
<span class='ivar'>@eff</span>
|
@@ -332,12 +332,12 @@
|
|
332
332
|
<pre class="lines">
|
333
333
|
|
334
334
|
|
335
|
-
|
336
|
-
|
337
|
-
|
335
|
+
29
|
336
|
+
30
|
337
|
+
31</pre>
|
338
338
|
</td>
|
339
339
|
<td>
|
340
|
-
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line
|
340
|
+
<pre class="code"><span class="info file"># File 'lib/ruff/objects.rb', line 29</span>
|
341
341
|
|
342
342
|
<span class='kw'>def</span> <span class='id identifier rubyid_k'>k</span>
|
343
343
|
<span class='ivar'>@k</span>
|
@@ -353,7 +353,7 @@
|
|
353
353
|
</div>
|
354
354
|
|
355
355
|
<div id="footer">
|
356
|
-
Generated on Thu Oct 3
|
356
|
+
Generated on Thu Oct 3 05:05:04 2019 by
|
357
357
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
358
358
|
0.9.20 (ruby-2.6.4).
|
359
359
|
</div>
|
data/docs/Ruff/Throws.html
CHANGED
@@ -110,7 +110,7 @@
|
|
110
110
|
</div>
|
111
111
|
|
112
112
|
<div id="footer">
|
113
|
-
Generated on Thu Oct 3
|
113
|
+
Generated on Thu Oct 3 05:05:04 2019 by
|
114
114
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
115
115
|
0.9.20 (ruby-2.6.4).
|
116
116
|
</div>
|
data/docs/Ruff.html
CHANGED
@@ -78,25 +78,14 @@
|
|
78
78
|
|
79
79
|
<dl>
|
80
80
|
<dt>Defined in:</dt>
|
81
|
-
<dd>lib/ruff
|
82
|
-
lib/ruff
|
81
|
+
<dd>lib/ruff.rb<span class="defines">,<br />
|
82
|
+
lib/ruff/version.rb</span>
|
83
83
|
</dd>
|
84
84
|
</dl>
|
85
85
|
|
86
86
|
</div>
|
87
87
|
|
88
|
-
<h2>
|
89
|
-
<div class="discussion">
|
90
|
-
<p>// This file is passed to CPP
|
91
|
-
include "../../version.h"</p>
|
92
|
-
|
93
|
-
|
94
|
-
</div>
|
95
|
-
</div>
|
96
|
-
<div class="tags">
|
97
|
-
|
98
|
-
|
99
|
-
</div><h2>Defined Under Namespace</h2>
|
88
|
+
<h2>Defined Under Namespace</h2>
|
100
89
|
<p class="children">
|
101
90
|
|
102
91
|
|
@@ -120,7 +109,7 @@ include "../../version.h"</p>
|
|
120
109
|
<dt id="VERSION-constant" class="">VERSION =
|
121
110
|
|
122
111
|
</dt>
|
123
|
-
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'
|
112
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1.0.0</span><span class='tstring_end'>'</span></span></pre></dd>
|
124
113
|
|
125
114
|
</dl>
|
126
115
|
|
@@ -237,12 +226,12 @@ include "../../version.h"</p>
|
|
237
226
|
<pre class="lines">
|
238
227
|
|
239
228
|
|
240
|
-
|
241
|
-
|
242
|
-
|
229
|
+
28
|
230
|
+
29
|
231
|
+
30</pre>
|
243
232
|
</td>
|
244
233
|
<td>
|
245
|
-
<pre class="code"><span class="info file"># File 'lib/ruff.rb', line
|
234
|
+
<pre class="code"><span class="info file"># File 'lib/ruff.rb', line 28</span>
|
246
235
|
|
247
236
|
<span class='kw'>def</span> <span class='id identifier rubyid_handler'>handler</span>
|
248
237
|
<span class='const'><span class='object_link'><a href="Ruff/Handler.html" title="Ruff::Handler (class)">Handler</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Ruff/Handler.html#initialize-instance_method" title="Ruff::Handler#initialize (method)">new</a></span></span>
|
@@ -292,12 +281,12 @@ include "../../version.h"</p>
|
|
292
281
|
<pre class="lines">
|
293
282
|
|
294
283
|
|
295
|
-
|
296
|
-
|
297
|
-
|
284
|
+
16
|
285
|
+
17
|
286
|
+
18</pre>
|
298
287
|
</td>
|
299
288
|
<td>
|
300
|
-
<pre class="code"><span class="info file"># File 'lib/ruff.rb', line
|
289
|
+
<pre class="code"><span class="info file"># File 'lib/ruff.rb', line 16</span>
|
301
290
|
|
302
291
|
<span class='kw'>def</span> <span class='id identifier rubyid_instance'>instance</span>
|
303
292
|
<span class='const'><span class='object_link'><a href="Ruff/Effect.html" title="Ruff::Effect (class)">Effect</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Ruff/Effect.html#initialize-instance_method" title="Ruff::Effect#initialize (method)">new</a></span></span>
|
@@ -312,7 +301,7 @@ include "../../version.h"</p>
|
|
312
301
|
</div>
|
313
302
|
|
314
303
|
<div id="footer">
|
315
|
-
Generated on Thu Oct 3
|
304
|
+
Generated on Thu Oct 3 05:05:04 2019 by
|
316
305
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
317
306
|
0.9.20 (ruby-2.6.4).
|
318
307
|
</div>
|
data/docs/_index.html
CHANGED
@@ -240,7 +240,7 @@
|
|
240
240
|
</div>
|
241
241
|
|
242
242
|
<div id="footer">
|
243
|
-
Generated on Thu Oct 3
|
243
|
+
Generated on Thu Oct 3 05:05:03 2019 by
|
244
244
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
245
245
|
0.9.20 (ruby-2.6.4).
|
246
246
|
</div>
|
data/docs/file.README.html
CHANGED
@@ -162,7 +162,7 @@
|
|
162
162
|
</div></div>
|
163
163
|
|
164
164
|
<div id="footer">
|
165
|
-
Generated on Thu Oct 3
|
165
|
+
Generated on Thu Oct 3 05:05:04 2019 by
|
166
166
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
167
167
|
0.9.20 (ruby-2.6.4).
|
168
168
|
</div>
|
data/docs/index.html
CHANGED
@@ -162,7 +162,7 @@
|
|
162
162
|
</div></div>
|
163
163
|
|
164
164
|
<div id="footer">
|
165
|
-
Generated on Thu Oct 3
|
165
|
+
Generated on Thu Oct 3 05:05:04 2019 by
|
166
166
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
167
167
|
0.9.20 (ruby-2.6.4).
|
168
168
|
</div>
|
@@ -100,7 +100,7 @@
|
|
100
100
|
</div>
|
101
101
|
|
102
102
|
<div id="footer">
|
103
|
-
Generated on Thu Oct 3
|
103
|
+
Generated on Thu Oct 3 05:05:04 2019 by
|
104
104
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
105
|
0.9.20 (ruby-2.6.4).
|
106
106
|
</div>
|
data/lib/ruff/effect.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This class provides an effect instance.
|
2
4
|
class Ruff::Effect
|
3
5
|
# Each instance must be unique so they have unique id with UUID
|
@@ -18,6 +20,6 @@ class Ruff::Effect
|
|
18
20
|
# @example
|
19
21
|
# Log.perform "hello"
|
20
22
|
def perform(*a)
|
21
|
-
|
23
|
+
Fiber.yield Ruff::Throws::Eff.new(@id, a)
|
22
24
|
end
|
23
25
|
end
|
data/lib/ruff/handler.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'securerandom'
|
2
4
|
|
3
5
|
# In algebraic effects, handler is an first-class object.
|
@@ -13,12 +15,10 @@ class Ruff::Handler
|
|
13
15
|
# handler = Handler.new
|
14
16
|
|
15
17
|
def initialize
|
16
|
-
@handlers =
|
17
|
-
@
|
18
|
-
@handlers[@valh_id] = ->(x) { x }
|
18
|
+
@handlers = {}
|
19
|
+
@valh = ->(x) { x }
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
22
|
# sets value handler `&fun`.
|
23
23
|
#
|
24
24
|
# Value handler is the handler for *the result value of the computation*.
|
@@ -54,7 +54,7 @@ class Ruff::Handler
|
|
54
54
|
# # returns !
|
55
55
|
|
56
56
|
def to(&fun)
|
57
|
-
@
|
57
|
+
@valh = fun
|
58
58
|
|
59
59
|
self
|
60
60
|
end
|
@@ -109,54 +109,51 @@ class Ruff::Handler
|
|
109
109
|
continue = nil
|
110
110
|
rehandles = nil
|
111
111
|
|
112
|
-
handle =
|
113
|
-
|
112
|
+
handle = lambda { |r|
|
113
|
+
case r
|
114
|
+
when Eff
|
114
115
|
if effh = @handlers[r.id]
|
115
116
|
effh[continue, *r.args]
|
116
117
|
else
|
117
118
|
Fiber.yield Resend.new(r, continue)
|
118
119
|
end
|
119
|
-
|
120
|
+
when Resend then
|
120
121
|
eff = r.eff
|
121
|
-
next_k = rehandles.(r.k)
|
122
|
+
next_k = rehandles.call(r.k)
|
122
123
|
|
123
124
|
if effh = @handlers[eff.id]
|
124
|
-
effh.(next_k, *eff.args)
|
125
|
+
effh.call(next_k, *eff.args)
|
125
126
|
else
|
126
127
|
Fiber.yield Resend.new(eff, next_k)
|
127
128
|
end
|
128
129
|
else
|
129
|
-
@
|
130
|
+
@valh.call(r)
|
130
131
|
end
|
131
132
|
}
|
132
133
|
|
133
|
-
rehandles =
|
134
|
+
rehandles = lambda { |k|
|
134
135
|
newh = self.class.new
|
135
|
-
def newh.add_handler
|
136
|
+
def newh.add_handler(id, h)
|
136
137
|
@handlers[id] = h
|
137
138
|
end
|
138
139
|
|
139
|
-
@handlers.each
|
140
|
+
@handlers.each do |id, h|
|
140
141
|
newh.add_handler id, h
|
141
|
-
|
142
|
+
end
|
142
143
|
|
143
144
|
class << newh
|
144
145
|
undef add_handler
|
145
146
|
end
|
146
147
|
|
147
|
-
|
148
|
-
continue
|
149
|
-
newh.run {
|
150
|
-
k.(*args)
|
151
|
-
}
|
152
|
-
]
|
148
|
+
lambda { |*args|
|
149
|
+
continue.call(newh.run { k.call(*args) })
|
153
150
|
}
|
154
151
|
}
|
155
152
|
|
156
|
-
continue =
|
157
|
-
handle.(co.resume(*arg))
|
153
|
+
continue = lambda { |*arg|
|
154
|
+
handle.call(co.resume(*arg))
|
158
155
|
}
|
159
156
|
|
160
|
-
continue.(nil)
|
157
|
+
continue.call(nil)
|
161
158
|
end
|
162
159
|
end
|
data/lib/ruff/objects.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ruff::Throws end
|
2
4
|
|
3
5
|
# `Eff` is internal object.
|
@@ -20,7 +22,7 @@ end
|
|
20
22
|
#
|
21
23
|
# It is used when an effect is unable to be handled and should be thrown to the outer handler.
|
22
24
|
class Ruff::Throws::Resend
|
23
|
-
#is abstracted effect (such as `Eff` or (re)thrown `Resend`).
|
25
|
+
# is abstracted effect (such as `Eff` or (re)thrown `Resend`).
|
24
26
|
attr_reader :eff
|
25
27
|
|
26
28
|
# is a continuation of `eff` thrown context.
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ruff::Standard::CurrentTime
|
2
4
|
class Instance
|
3
5
|
def initialize
|
@@ -8,8 +10,8 @@ module Ruff::Standard::CurrentTime
|
|
8
10
|
@eff.perform
|
9
11
|
end
|
10
12
|
|
11
|
-
def with
|
12
|
-
Ruff.handler.on(@eff){|k| k[Time.now]}.run &th
|
13
|
+
def with(&th)
|
14
|
+
Ruff.handler.on(@eff) { |k| k[Time.now] }.run &th
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
@@ -20,10 +22,9 @@ module Ruff::Standard::CurrentTime
|
|
20
22
|
@inst.get
|
21
23
|
end
|
22
24
|
|
23
|
-
def with
|
25
|
+
def with(&th)
|
24
26
|
@inst.with &th
|
25
27
|
end
|
26
28
|
|
27
29
|
module_function :get, :with
|
28
30
|
end
|
29
|
-
|
data/lib/ruff/standard/defer.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ruff::Standard::Defer
|
2
4
|
class Instance
|
3
5
|
def initialize
|
4
6
|
@eff = Ruff.instance
|
5
7
|
end
|
6
8
|
|
7
|
-
def register
|
9
|
+
def register(&prc)
|
8
10
|
@eff.perform prc
|
9
11
|
end
|
10
12
|
|
11
|
-
def with
|
13
|
+
def with(&th)
|
12
14
|
procs = []
|
13
15
|
|
14
16
|
Ruff.handler
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
24
|
-
.run &th
|
17
|
+
.on(@eff) do |k, prc|
|
18
|
+
procs << prc
|
19
|
+
k[]
|
20
|
+
end
|
21
|
+
.to do |_|
|
22
|
+
procs.reverse_each(&:[])
|
23
|
+
end
|
24
|
+
.run &th
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
# ---
|
29
29
|
@inst = Instance.new
|
30
30
|
|
31
|
-
def register
|
31
|
+
def register(&prc)
|
32
32
|
@inst.register &prc
|
33
33
|
end
|
34
34
|
|
35
|
-
def with
|
35
|
+
def with(&th)
|
36
36
|
@inst.with &th
|
37
37
|
end
|
38
38
|
|
data/lib/ruff/standard/state.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ruff::Standard::State
|
2
4
|
class Instance
|
3
5
|
def initialize
|
@@ -9,29 +11,29 @@ module Ruff::Standard::State
|
|
9
11
|
@get.perform
|
10
12
|
end
|
11
13
|
|
12
|
-
def modify
|
14
|
+
def modify(&fn)
|
13
15
|
@modify.perform fn
|
14
16
|
end
|
15
17
|
|
16
|
-
def put
|
18
|
+
def put(s)
|
17
19
|
@modify.perform ->(_) { s }
|
18
20
|
end
|
19
21
|
|
20
|
-
def with_init
|
22
|
+
def with_init(init, &task)
|
21
23
|
state = init
|
22
24
|
|
23
25
|
Ruff.handler
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
.on(@modify) do |k, fn|
|
27
|
+
state = fn[state]
|
28
|
+
k[nil]
|
29
|
+
end
|
30
|
+
.on(@get) do |k|
|
31
|
+
k[state]
|
32
|
+
end
|
33
|
+
.run &task
|
32
34
|
end
|
33
35
|
|
34
|
-
def with
|
36
|
+
def with(&task)
|
35
37
|
with_init(nil, &task)
|
36
38
|
end
|
37
39
|
end
|
@@ -43,22 +45,21 @@ module Ruff::Standard::State
|
|
43
45
|
@inst.get
|
44
46
|
end
|
45
47
|
|
46
|
-
def modify
|
48
|
+
def modify(&fn)
|
47
49
|
@inst.modify &fn
|
48
50
|
end
|
49
51
|
|
50
|
-
def put
|
52
|
+
def put(s)
|
51
53
|
@inst.put s
|
52
54
|
end
|
53
55
|
|
54
|
-
def with_init
|
56
|
+
def with_init(init, &task)
|
55
57
|
@inst.with_init init, &task
|
56
58
|
end
|
57
59
|
|
58
|
-
def with
|
60
|
+
def with(&task)
|
59
61
|
@inst.with &task
|
60
62
|
end
|
61
63
|
|
62
64
|
module_function :get, :put, :modify, :with, :with_init
|
63
65
|
end
|
64
|
-
|