mangrove 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -0
- data/README.md +58 -14
- data/Rakefile +16 -3
- data/docs/Mangrove/ControlFlow/ControlSignal.html +223 -0
- data/docs/Mangrove/ControlFlow/Handler/ClassMethods.html +563 -0
- data/docs/Mangrove/ControlFlow/Handler.html +139 -0
- data/docs/Mangrove/ControlFlow/Rewriter.html +331 -0
- data/docs/Mangrove/ControlFlow.html +254 -0
- data/docs/Mangrove/Option/ControlSignal.html +434 -0
- data/docs/Mangrove/Option/None.html +889 -0
- data/docs/Mangrove/Option/Some.html +1019 -0
- data/docs/Mangrove/Option.html +853 -0
- data/docs/Mangrove/Result/ControlSignal.html +434 -0
- data/docs/Mangrove/Result/Err.html +953 -0
- data/docs/Mangrove/Result/Ok.html +927 -0
- data/docs/Mangrove/Result.html +889 -0
- data/docs/Mangrove.html +144 -0
- data/docs/_index.html +257 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +497 -0
- data/docs/file.README.html +176 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +176 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +595 -0
- data/docs/top-level-namespace.html +110 -0
- data/hooks/pre-push +2 -0
- data/lib/mangrove/control_flow/rewriter.rb +5 -2
- data/lib/mangrove/result.rb +46 -37
- data/lib/mangrove/version.rb +1 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d918f24a3f566f944a31d9eac30ab5f4924c69260ac95977cca466fb758f32fa
|
4
|
+
data.tar.gz: 6a2f8b8dc58cbb9a3b51d79834cd0a342671dbc5c4d870ae238bd756f6c2fe12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc901c133dd8b64466ab1f5a900f2469e17564cb5a7e7b7db13e3714f094dd400877ed214383500229d3e98d51c457427044df78afbc28a96b48fba29e6e91cb
|
7
|
+
data.tar.gz: 890c8fbd972e5c2b87e6ffde50eda4b98c45105419fd43abac76644781bcb4f5dd8d2ee736877f2a4198c0a068a0b2732a89fb40c5607ced5fc5ac7897208ed6
|
data/.rubocop.yml
CHANGED
@@ -9,6 +9,9 @@ Layout/FirstArrayElementIndentation:
|
|
9
9
|
Layout/LineLength:
|
10
10
|
Enabled: false
|
11
11
|
|
12
|
+
Layout/MultilineMethodCallIndentation:
|
13
|
+
EnforcedStyle: indented
|
14
|
+
|
12
15
|
Metrics/AbcSize:
|
13
16
|
Enabled: false
|
14
17
|
|
@@ -27,6 +30,13 @@ Metrics/ModuleLength:
|
|
27
30
|
Naming/VariableNumber:
|
28
31
|
EnforcedStyle: snake_case
|
29
32
|
|
33
|
+
Style/BlockDelimiters:
|
34
|
+
EnforcedStyle: always_braces
|
35
|
+
AllowedMethods:
|
36
|
+
- describe
|
37
|
+
- context
|
38
|
+
- it
|
39
|
+
|
30
40
|
Style/Documentation:
|
31
41
|
Enabled: false
|
32
42
|
|
data/README.md
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
# Mangrove
|
2
|
-
Mangrove provides utility
|
2
|
+
Mangrove provides type utility to use with Sorbet.
|
3
|
+
|
4
|
+
You can do something like this with the gem.
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
class MyClass
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
include Mangrove::ControlFlow::Handler
|
11
|
+
|
12
|
+
sig { params(numbers: T::Enumerable[Integer]).returns(Mangrove::Result[T::Array[Integer], String]) }
|
13
|
+
def divide_arguments_by_3(numbers)
|
14
|
+
divided_nubmers = numbers
|
15
|
+
.map { |number|
|
16
|
+
if number % 3 == 0
|
17
|
+
Mangrove::Result::Ok.new(number / 3)
|
18
|
+
else
|
19
|
+
Mangrove::Result::Err.new("number #{number} is not divisible by 3")
|
20
|
+
end
|
21
|
+
}
|
22
|
+
.map(&:unwrap!)
|
23
|
+
|
24
|
+
Mangrove::Result::Ok.new(divided_nubmers)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
expect(MyClass.new.divide_arguments_by_3([3, 4, 6])).to eq Mangrove::Result::Err.new("number 4 is not divisible by 3")
|
29
|
+
expect(MyClass.new.divide_arguments_by_3([3, 6, 9])).to eq Mangrove::Result::Ok.new([1, 2, 3])
|
30
|
+
```
|
31
|
+
|
32
|
+
Other examples are available at [`spec/**/**_spec.rb`](https://github.com/kazzix14/mangrove/tree/main/spec).
|
3
33
|
|
4
34
|
## Features
|
5
35
|
Most features are not implemented.
|
@@ -10,27 +40,40 @@ Most features are not implemented.
|
|
10
40
|
- [x] Auto propagation like Rust's `?` (formerly `try!`)
|
11
41
|
- [ ] Builder type (Not implemented)
|
12
42
|
- [ ] Auto Implementation
|
13
|
-
|
14
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mangrove`. To experiment with that code, run `bin/console` for an interactive prompt.
|
43
|
+
- [ ] TODO
|
15
44
|
|
16
45
|
## Installation
|
17
46
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
23
|
-
|
24
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
25
|
-
|
26
|
-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
47
|
+
```
|
48
|
+
bundle add mangrove
|
49
|
+
```
|
27
50
|
|
28
51
|
## Usage
|
29
52
|
|
30
|
-
|
53
|
+
Documentation is available [here](https://kazzix14.github.io/mangrove/).
|
54
|
+
For more concrete examples, see [`spec/**/**_spec.rb`](https://github.com/kazzix14/mangrove/tree/main/spec).
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
Mangrove::Result[OkType, ErrType]
|
58
|
+
Mangrove::Result::Ok[OkType, ErrType]
|
59
|
+
Mangrove::Result::Err[OkType, ErrType]
|
60
|
+
Mangrove::Option[InnerType]
|
61
|
+
Mangrove::Option::Some[InnerType]
|
62
|
+
Mangrove::Option::None[InnerType]
|
63
|
+
|
64
|
+
my_ok = Result::Ok.new("my value")
|
65
|
+
my_err = Result::Err.new("my err")
|
66
|
+
my_some = Option::Some.new(1234)
|
67
|
+
my_none = Option::None.new
|
68
|
+
|
69
|
+
# Including this Module into your class appends rescue clause into its methods. Results to `Option#unwrap!` and `Result#unwrap!` propagates to calling method like Ruet's `?` operator.
|
70
|
+
# https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator
|
71
|
+
include Mangrove::ControlFlow::Handler
|
72
|
+
```
|
31
73
|
|
32
74
|
## Commands
|
33
75
|
```
|
76
|
+
git config core.hooksPath hooks
|
34
77
|
bundle exec tapioca init
|
35
78
|
bundle exec tapioca gems
|
36
79
|
bundle exec tapioca dsl
|
@@ -41,6 +84,7 @@ bundle exec rubocop -DESP
|
|
41
84
|
bundle exec srb typecheck
|
42
85
|
bundle exec ordinare --check
|
43
86
|
bundle exec ruboclean
|
87
|
+
bundle exec yardoc -o docs/ --plugin yard-sorbet
|
44
88
|
rake build
|
45
89
|
rake release
|
46
90
|
```
|
@@ -53,4 +97,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
53
97
|
|
54
98
|
## Contributing
|
55
99
|
|
56
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
100
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kazzix14/mangrove.
|
data/Rakefile
CHANGED
@@ -3,12 +3,25 @@
|
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
require "rake/testtask"
|
5
5
|
|
6
|
-
task
|
6
|
+
task(:check) {
|
7
7
|
system("bundle exec ordinare --check") &&
|
8
8
|
system("bundle exec rubocop -DESP") &&
|
9
9
|
system("bundle exec tapioca check-shims") &&
|
10
10
|
system("bundle exec srb typecheck") &&
|
11
|
-
system("bundle exec rspec -f d")
|
12
|
-
|
11
|
+
system("bundle exec rspec -f d") &&
|
12
|
+
# check doc version
|
13
|
+
system(
|
14
|
+
<<~SHELL
|
15
|
+
gem_version=`bundle info mangrove | grep -o '[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+'`
|
16
|
+
doc_version=`grep 'VERSION =' docs/Mangrove.html -A 5 | grep -o '[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+'`
|
17
|
+
|
18
|
+
if [ "$gem_version" = "$doc_version" ]; then
|
19
|
+
exit 0
|
20
|
+
else
|
21
|
+
exit 1
|
22
|
+
fi
|
23
|
+
SHELL
|
24
|
+
)
|
25
|
+
}
|
13
26
|
|
14
27
|
task default: :check
|
@@ -0,0 +1,223 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Module: Mangrove::ControlFlow::ControlSignal
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.34
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../../css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../../css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "Mangrove::ControlFlow::ControlSignal";
|
19
|
+
relpath = '../../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="../../class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../../_index.html">Index (C)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../../Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span> » <span class='title'><span class='object_link'><a href="../ControlFlow.html" title="Mangrove::ControlFlow (module)">ControlFlow</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">ControlSignal</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Module: Mangrove::ControlFlow::ControlSignal
|
63
|
+
<span class="abstract note title">Abstract</span>
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
<dl>
|
73
|
+
<dt>Extended by:</dt>
|
74
|
+
<dd>T::Helpers, T::Sig</dd>
|
75
|
+
</dl>
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
<dl>
|
83
|
+
<dt>Included in:</dt>
|
84
|
+
<dd><span class='object_link'><a href="../Option/ControlSignal.html" title="Mangrove::Option::ControlSignal (class)">Option::ControlSignal</a></span>, <span class='object_link'><a href="../Result/ControlSignal.html" title="Mangrove::Result::ControlSignal (class)">Result::ControlSignal</a></span></dd>
|
85
|
+
</dl>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
<dl>
|
90
|
+
<dt>Defined in:</dt>
|
91
|
+
<dd>lib/mangrove/control_flow/control_signal.rb</dd>
|
92
|
+
</dl>
|
93
|
+
|
94
|
+
</div>
|
95
|
+
|
96
|
+
<h2>Overview</h2><div class="docstring">
|
97
|
+
<div class="discussion">
|
98
|
+
<div class="note abstract">
|
99
|
+
<strong>This module is abstract.</strong>
|
100
|
+
<div class='inline'>
|
101
|
+
<p>Subclasses must implement the ‘abstract` methods below.</p>
|
102
|
+
</div>
|
103
|
+
</div>
|
104
|
+
|
105
|
+
|
106
|
+
</div>
|
107
|
+
</div>
|
108
|
+
<div class="tags">
|
109
|
+
|
110
|
+
|
111
|
+
</div>
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
<h2>
|
120
|
+
Instance Method Summary
|
121
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
122
|
+
</h2>
|
123
|
+
|
124
|
+
<ul class="summary">
|
125
|
+
|
126
|
+
<li class="public ">
|
127
|
+
<span class="summary_signature">
|
128
|
+
|
129
|
+
<a href="#inner_value-instance_method" title="#inner_value (instance method)">#<strong>inner_value</strong> ⇒ T.untyped </a>
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
</span>
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
<span class="abstract note title">abstract</span>
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
144
|
+
|
145
|
+
</li>
|
146
|
+
|
147
|
+
|
148
|
+
</ul>
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
<div id="instance_method_details" class="method_details_list">
|
156
|
+
<h2>Instance Method Details</h2>
|
157
|
+
|
158
|
+
|
159
|
+
<div class="method_details first">
|
160
|
+
<h3 class="signature first" id="inner_value-instance_method">
|
161
|
+
|
162
|
+
#<strong>inner_value</strong> ⇒ <tt>T.untyped</tt>
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
</h3><div class="docstring">
|
169
|
+
<div class="discussion">
|
170
|
+
<div class="note abstract">
|
171
|
+
<strong>This method is abstract.</strong>
|
172
|
+
<div class='inline'></div>
|
173
|
+
</div>
|
174
|
+
|
175
|
+
|
176
|
+
</div>
|
177
|
+
</div>
|
178
|
+
<div class="tags">
|
179
|
+
|
180
|
+
<p class="tag_title">Returns:</p>
|
181
|
+
<ul class="return">
|
182
|
+
|
183
|
+
<li>
|
184
|
+
|
185
|
+
|
186
|
+
<span class='type'>(<tt>T.untyped</tt>)</span>
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
</li>
|
191
|
+
|
192
|
+
</ul>
|
193
|
+
|
194
|
+
</div><table class="source_code">
|
195
|
+
<tr>
|
196
|
+
<td>
|
197
|
+
<pre class="lines">
|
198
|
+
|
199
|
+
|
200
|
+
13</pre>
|
201
|
+
</td>
|
202
|
+
<td>
|
203
|
+
<pre class="code"><span class="info file"># File 'lib/mangrove/control_flow/control_signal.rb', line 13</span>
|
204
|
+
|
205
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_inner_value'>inner_value</span><span class='semicolon'>;</span> <span class='kw'>end</span></pre>
|
206
|
+
</td>
|
207
|
+
</tr>
|
208
|
+
</table>
|
209
|
+
</div>
|
210
|
+
|
211
|
+
</div>
|
212
|
+
|
213
|
+
</div>
|
214
|
+
|
215
|
+
<div id="footer">
|
216
|
+
Generated on Thu Aug 31 15:04:25 2023 by
|
217
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
218
|
+
0.9.34 (ruby-3.2.2).
|
219
|
+
</div>
|
220
|
+
|
221
|
+
</div>
|
222
|
+
</body>
|
223
|
+
</html>
|