mangrove 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +82 -9
- data/docs/Mangrove/ControlFlow/ControlSignal.html +1 -1
- data/docs/Mangrove/ControlFlow.html +1 -1
- data/docs/Mangrove/Option/ControlSignal.html +1 -1
- data/docs/Mangrove/Option/None.html +1 -1
- data/docs/Mangrove/Option/Some.html +1 -1
- data/docs/Mangrove/Option.html +1 -1
- data/docs/Mangrove/Result/ControlSignal.html +1 -1
- data/docs/Mangrove/Result/Err.html +2 -2
- data/docs/Mangrove/Result/Ok.html +2 -2
- data/docs/Mangrove/Result.html +10 -10
- data/docs/Mangrove.html +2 -2
- data/docs/_index.html +1 -1
- data/docs/file.README.html +82 -10
- data/docs/index.html +82 -10
- data/docs/top-level-namespace.html +1 -1
- data/lib/mangrove/result.rb +13 -13
- data/lib/mangrove/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 617875ba6ae95633c64ead5888103f6eefe1ae4075311f3d0ac8e8388b6e83b7
|
4
|
+
data.tar.gz: 5ba2a9cf035c045a4508a5cedf4fefeb3d60305ea3ac0ce7cfb2c8b793e077ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 984034dc5a95309b01351c22287762162ddf2f946507246871c7feb66eeda328f6f43549fc80bcee6998c81675ecd8ab4fe6e05334102d8124992eb07e15d788
|
7
|
+
data.tar.gz: '094bc86b4591e76f10076794bf198f3eaf85fec096dcf27dd35d33299f06bed9132a23379e30e0150764087e6b28ff4ae71d9efeff0624f008f90c4808002b91'
|
data/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
# Mangrove
|
2
2
|
Mangrove provides type utility to use with Sorbet.
|
3
|
+
use `rubocop-mangrove` to statically check rescuing ControlSignal is done
|
3
4
|
|
4
5
|
You can do something like this with the gem.
|
5
|
-
|
6
|
-
use `rubocop-mangrove`` to statically check rescuing ControlSignal is done
|
7
|
-
|
8
6
|
```ruby
|
9
7
|
class TransposeExample
|
10
8
|
extend T::Sig
|
@@ -27,6 +25,85 @@ end
|
|
27
25
|
|
28
26
|
expect(TransposeExample.new.divide_arguments_by_3([3, 4, 5])).to eq Mangrove::Result::Err.new(["number 4 is not divisible by 3", "number 5 is not divisible by 3"])
|
29
27
|
expect(TransposeExample.new.divide_arguments_by_3([3, 6, 9])).to eq Mangrove::Result::Ok.new([1, 2, 3])
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
or like this.
|
32
|
+
```ruby
|
33
|
+
class MyController
|
34
|
+
extend T::Sig
|
35
|
+
|
36
|
+
sig { params(input: String).returns(String) }
|
37
|
+
def create(input)
|
38
|
+
result = MyService.new.execute(input)
|
39
|
+
|
40
|
+
case result
|
41
|
+
when Mangrove::Result::Ok
|
42
|
+
result.ok_inner
|
43
|
+
when Mangrove::Result::Err
|
44
|
+
error = result.err_inner
|
45
|
+
|
46
|
+
case error
|
47
|
+
when MyService::MyServiceError::E1
|
48
|
+
"e1: #{error.inner.msg}"
|
49
|
+
when MyService::MyServiceError::E2
|
50
|
+
"e2: #{error.inner.msg}"
|
51
|
+
when MyService::MyServiceError::Other
|
52
|
+
"other: #{error.inner.msg}"
|
53
|
+
else T.absurd(error)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class MyService
|
60
|
+
extend T::Sig
|
61
|
+
extend T::Generic
|
62
|
+
|
63
|
+
include Kernel
|
64
|
+
|
65
|
+
E = type_member { { upper: MyServiceError } }
|
66
|
+
|
67
|
+
sig { params(input: String).returns(Mangrove::Result[String, MyServiceError]) }
|
68
|
+
def execute(input)
|
69
|
+
input
|
70
|
+
.safe_to_i
|
71
|
+
.map_err_wt(MyServiceError::Other) { |e|
|
72
|
+
MyServiceError::Other.new(MyAppError::Other.new(e)).as_my_service_error
|
73
|
+
}.and_then_wt(String) { |num|
|
74
|
+
if num < 1
|
75
|
+
Mangrove::Result.err(String, MyServiceError::E1.new(MyAppError::E1.new("num < 1")).as_my_service_error)
|
76
|
+
elsif num < 3
|
77
|
+
Mangrove::Result
|
78
|
+
.ok(num, String)
|
79
|
+
.and_then_wt(String) { |n|
|
80
|
+
if n < 2
|
81
|
+
Mangrove::Result.ok("`#{n}` < 2", String)
|
82
|
+
else
|
83
|
+
Mangrove::Result.err(String, "not `#{n}` < 2")
|
84
|
+
end
|
85
|
+
}
|
86
|
+
.map_err_wt(MyServiceError::E1) { |e|
|
87
|
+
MyServiceError::E1.new(MyAppError::E1.new("mapping to E1 #{e}")).as_my_service_error
|
88
|
+
}
|
89
|
+
.map_ok { |str|
|
90
|
+
{
|
91
|
+
my_key: str
|
92
|
+
}
|
93
|
+
}
|
94
|
+
.map_ok(&:to_s)
|
95
|
+
else
|
96
|
+
Mangrove::Result.err(String, MyServiceError::E2.new(MyAppError::E2.new).as_my_service_error)
|
97
|
+
end
|
98
|
+
}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
expect(MyController.new.create("0")).to eq "e1: num < 1"
|
103
|
+
expect(MyController.new.create("1")).to eq "{:my_key=>\"`1` < 2\"}"
|
104
|
+
expect(MyController.new.create("2")).to eq "e1: mapping to E1 not `2` < 2"
|
105
|
+
expect(MyController.new.create("3")).to eq "e2: e2"
|
106
|
+
expect(MyController.new.create("invalid")).to eq "other: invalid value for Integer(): \"invalid\""
|
30
107
|
```
|
31
108
|
|
32
109
|
Other examples are available at [`spec/**/**_spec.rb`](https://github.com/kazzix14/mangrove/tree/main/spec).
|
@@ -48,7 +125,7 @@ bundle add mangrove
|
|
48
125
|
|
49
126
|
## Usage
|
50
127
|
|
51
|
-
Documentation is available
|
128
|
+
[Documentation is available here](https://kazzix14.github.io/mangrove/).
|
52
129
|
For more concrete examples, see [`spec/**/**_spec.rb`](https://github.com/kazzix14/mangrove/tree/main/spec).
|
53
130
|
|
54
131
|
```ruby
|
@@ -63,13 +140,9 @@ my_ok = Result::Ok.new("my value")
|
|
63
140
|
my_err = Result::Err.new("my err")
|
64
141
|
my_some = Option::Some.new(1234)
|
65
142
|
my_none = Option::None.new
|
66
|
-
|
67
|
-
# 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.
|
68
|
-
# https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator
|
69
|
-
include Mangrove::ControlFlow::Handler
|
70
143
|
```
|
71
144
|
|
72
|
-
## Commands
|
145
|
+
## Commands for Development
|
73
146
|
```
|
74
147
|
git config core.hooksPath hooks
|
75
148
|
bundle exec tapioca init
|
@@ -213,7 +213,7 @@
|
|
213
213
|
</div>
|
214
214
|
|
215
215
|
<div id="footer">
|
216
|
-
Generated on
|
216
|
+
Generated on Wed Nov 1 14:25:08 2023 by
|
217
217
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
218
218
|
0.9.34 (ruby-3.2.2).
|
219
219
|
</div>
|
@@ -105,7 +105,7 @@
|
|
105
105
|
</div>
|
106
106
|
|
107
107
|
<div id="footer">
|
108
|
-
Generated on
|
108
|
+
Generated on Wed Nov 1 14:25:08 2023 by
|
109
109
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
110
110
|
0.9.34 (ruby-3.2.2).
|
111
111
|
</div>
|
@@ -424,7 +424,7 @@
|
|
424
424
|
</div>
|
425
425
|
|
426
426
|
<div id="footer">
|
427
|
-
Generated on
|
427
|
+
Generated on Wed Nov 1 14:25:09 2023 by
|
428
428
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
429
429
|
0.9.34 (ruby-3.2.2).
|
430
430
|
</div>
|
@@ -1075,7 +1075,7 @@
|
|
1075
1075
|
</div>
|
1076
1076
|
|
1077
1077
|
<div id="footer">
|
1078
|
-
Generated on
|
1078
|
+
Generated on Wed Nov 1 14:25:08 2023 by
|
1079
1079
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1080
1080
|
0.9.34 (ruby-3.2.2).
|
1081
1081
|
</div>
|
@@ -1192,7 +1192,7 @@
|
|
1192
1192
|
</div>
|
1193
1193
|
|
1194
1194
|
<div id="footer">
|
1195
|
-
Generated on
|
1195
|
+
Generated on Wed Nov 1 14:25:08 2023 by
|
1196
1196
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1197
1197
|
0.9.34 (ruby-3.2.2).
|
1198
1198
|
</div>
|
data/docs/Mangrove/Option.html
CHANGED
@@ -1135,7 +1135,7 @@
|
|
1135
1135
|
</div>
|
1136
1136
|
|
1137
1137
|
<div id="footer">
|
1138
|
-
Generated on
|
1138
|
+
Generated on Wed Nov 1 14:25:08 2023 by
|
1139
1139
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1140
1140
|
0.9.34 (ruby-3.2.2).
|
1141
1141
|
</div>
|
@@ -424,7 +424,7 @@
|
|
424
424
|
</div>
|
425
425
|
|
426
426
|
<div id="footer">
|
427
|
-
Generated on
|
427
|
+
Generated on Wed Nov 1 14:25:09 2023 by
|
428
428
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
429
429
|
0.9.34 (ruby-3.2.2).
|
430
430
|
</div>
|
@@ -1193,7 +1193,7 @@
|
|
1193
1193
|
<span class='name'>block</span>
|
1194
1194
|
|
1195
1195
|
|
1196
|
-
<span class='type'>(<tt>T.proc.returns(T.
|
1196
|
+
<span class='type'>(<tt>T.proc.returns(T.type_parameter(:E))</tt>)</span>
|
1197
1197
|
|
1198
1198
|
|
1199
1199
|
|
@@ -2079,7 +2079,7 @@
|
|
2079
2079
|
</div>
|
2080
2080
|
|
2081
2081
|
<div id="footer">
|
2082
|
-
Generated on
|
2082
|
+
Generated on Wed Nov 1 14:25:09 2023 by
|
2083
2083
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
2084
2084
|
0.9.34 (ruby-3.2.2).
|
2085
2085
|
</div>
|
@@ -1130,7 +1130,7 @@
|
|
1130
1130
|
<span class='name'>_block</span>
|
1131
1131
|
|
1132
1132
|
|
1133
|
-
<span class='type'>(<tt>T.proc.returns(T.
|
1133
|
+
<span class='type'>(<tt>T.proc.returns(T.type_parameter(:E))</tt>)</span>
|
1134
1134
|
|
1135
1135
|
|
1136
1136
|
|
@@ -2044,7 +2044,7 @@
|
|
2044
2044
|
</div>
|
2045
2045
|
|
2046
2046
|
<div id="footer">
|
2047
|
-
Generated on
|
2047
|
+
Generated on Wed Nov 1 14:25:09 2023 by
|
2048
2048
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
2049
2049
|
0.9.34 (ruby-3.2.2).
|
2050
2050
|
</div>
|
data/docs/Mangrove/Result.html
CHANGED
@@ -139,12 +139,12 @@
|
|
139
139
|
<dt id="OkType-constant" class="">OkType =
|
140
140
|
|
141
141
|
</dt>
|
142
|
-
<dd><pre class="code"><span class='id identifier rubyid_type_member'>type_member</span
|
142
|
+
<dd><pre class="code"><span class='id identifier rubyid_type_member'>type_member</span></pre></dd>
|
143
143
|
|
144
144
|
<dt id="ErrType-constant" class="">ErrType =
|
145
145
|
|
146
146
|
</dt>
|
147
|
-
<dd><pre class="code"><span class='id identifier rubyid_type_member'>type_member</span
|
147
|
+
<dd><pre class="code"><span class='id identifier rubyid_type_member'>type_member</span></pre></dd>
|
148
148
|
|
149
149
|
</dl>
|
150
150
|
|
@@ -987,7 +987,7 @@
|
|
987
987
|
<span class='name'>other</span>
|
988
988
|
|
989
989
|
|
990
|
-
<span class='type'>(<tt><span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[T.type_parameter(:NewOkType),
|
990
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[T.type_parameter(:NewOkType), <span class='object_link'><a href="#ErrType-constant" title="Mangrove::Result::ErrType (constant)">ErrType</a></span>]</tt>)</span>
|
991
991
|
|
992
992
|
|
993
993
|
|
@@ -1054,7 +1054,7 @@
|
|
1054
1054
|
<span class='name'>block</span>
|
1055
1055
|
|
1056
1056
|
|
1057
|
-
<span class='type'>(<tt>T.proc.params(this: <span class='object_link'><a href="#OkType-constant" title="Mangrove::Result::OkType (constant)">OkType</a></span>).returns(<span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[T.type_parameter(:NewOkType),
|
1057
|
+
<span class='type'>(<tt>T.proc.params(this: <span class='object_link'><a href="#OkType-constant" title="Mangrove::Result::OkType (constant)">OkType</a></span>).returns(<span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[T.type_parameter(:NewOkType), <span class='object_link'><a href="#ErrType-constant" title="Mangrove::Result::ErrType (constant)">ErrType</a></span>])</tt>)</span>
|
1058
1058
|
|
1059
1059
|
|
1060
1060
|
|
@@ -1132,7 +1132,7 @@
|
|
1132
1132
|
<span class='name'>block</span>
|
1133
1133
|
|
1134
1134
|
|
1135
|
-
<span class='type'>(<tt>T.proc.params(this: <span class='object_link'><a href="#OkType-constant" title="Mangrove::Result::OkType (constant)">OkType</a></span>).returns(<span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[T.type_parameter(:NewOkType),
|
1135
|
+
<span class='type'>(<tt>T.proc.params(this: <span class='object_link'><a href="#OkType-constant" title="Mangrove::Result::OkType (constant)">OkType</a></span>).returns(<span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[T.type_parameter(:NewOkType), <span class='object_link'><a href="#ErrType-constant" title="Mangrove::Result::ErrType (constant)">ErrType</a></span>])</tt>)</span>
|
1136
1136
|
|
1137
1137
|
|
1138
1138
|
|
@@ -1318,7 +1318,7 @@
|
|
1318
1318
|
<span class='name'>block</span>
|
1319
1319
|
|
1320
1320
|
|
1321
|
-
<span class='type'>(<tt>T.proc.returns(T.
|
1321
|
+
<span class='type'>(<tt>T.proc.returns(T.type_parameter(:E))</tt>)</span>
|
1322
1322
|
|
1323
1323
|
|
1324
1324
|
|
@@ -1883,7 +1883,7 @@
|
|
1883
1883
|
<span class='name'>other</span>
|
1884
1884
|
|
1885
1885
|
|
1886
|
-
<span class='type'>(<tt><span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[
|
1886
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[<span class='object_link'><a href="#OkType-constant" title="Mangrove::Result::OkType (constant)">OkType</a></span>, <span class='object_link'><a href="#ErrType-constant" title="Mangrove::Result::ErrType (constant)">ErrType</a></span>]</tt>)</span>
|
1887
1887
|
|
1888
1888
|
|
1889
1889
|
|
@@ -1950,7 +1950,7 @@
|
|
1950
1950
|
<span class='name'>block</span>
|
1951
1951
|
|
1952
1952
|
|
1953
|
-
<span class='type'>(<tt>T.proc.params(this: <span class='object_link'><a href="#ErrType-constant" title="Mangrove::Result::ErrType (constant)">ErrType</a></span>).returns(<span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[
|
1953
|
+
<span class='type'>(<tt>T.proc.params(this: <span class='object_link'><a href="#ErrType-constant" title="Mangrove::Result::ErrType (constant)">ErrType</a></span>).returns(<span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[<span class='object_link'><a href="#OkType-constant" title="Mangrove::Result::OkType (constant)">OkType</a></span>, T.type_parameter(:NewErrType)])</tt>)</span>
|
1954
1954
|
|
1955
1955
|
|
1956
1956
|
|
@@ -2028,7 +2028,7 @@
|
|
2028
2028
|
<span class='name'>block</span>
|
2029
2029
|
|
2030
2030
|
|
2031
|
-
<span class='type'>(<tt>T.proc.params(this: <span class='object_link'><a href="#ErrType-constant" title="Mangrove::Result::ErrType (constant)">ErrType</a></span>).returns(<span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[
|
2031
|
+
<span class='type'>(<tt>T.proc.params(this: <span class='object_link'><a href="#ErrType-constant" title="Mangrove::Result::ErrType (constant)">ErrType</a></span>).returns(<span class='object_link'><a href="" title="Mangrove::Result (module)">Result</a></span>[<span class='object_link'><a href="#OkType-constant" title="Mangrove::Result::OkType (constant)">OkType</a></span>, T.type_parameter(:NewErrType)])</tt>)</span>
|
2032
2032
|
|
2033
2033
|
|
2034
2034
|
|
@@ -2124,7 +2124,7 @@
|
|
2124
2124
|
</div>
|
2125
2125
|
|
2126
2126
|
<div id="footer">
|
2127
|
-
Generated on
|
2127
|
+
Generated on Wed Nov 1 14:25:08 2023 by
|
2128
2128
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
2129
2129
|
0.9.34 (ruby-3.2.2).
|
2130
2130
|
</div>
|
data/docs/Mangrove.html
CHANGED
@@ -118,7 +118,7 @@
|
|
118
118
|
<dt id="VERSION-constant" class="">VERSION =
|
119
119
|
|
120
120
|
</dt>
|
121
|
-
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.
|
121
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0.16.0</span><span class='tstring_end'>"</span></span></pre></dd>
|
122
122
|
|
123
123
|
</dl>
|
124
124
|
|
@@ -134,7 +134,7 @@
|
|
134
134
|
</div>
|
135
135
|
|
136
136
|
<div id="footer">
|
137
|
-
Generated on
|
137
|
+
Generated on Wed Nov 1 14:25:08 2023 by
|
138
138
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
139
139
|
0.9.34 (ruby-3.2.2).
|
140
140
|
</div>
|
data/docs/_index.html
CHANGED
@@ -215,7 +215,7 @@
|
|
215
215
|
</div>
|
216
216
|
|
217
217
|
<div id="footer">
|
218
|
-
Generated on
|
218
|
+
Generated on Wed Nov 1 14:25:07 2023 by
|
219
219
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
220
220
|
0.9.34 (ruby-3.2.2).
|
221
221
|
</div>
|
data/docs/file.README.html
CHANGED
@@ -60,12 +60,10 @@
|
|
60
60
|
<div id="content"><div id='filecontents'>
|
61
61
|
<h1 id="label-Mangrove">Mangrove</h1>
|
62
62
|
|
63
|
-
<p>Mangrove provides type utility to use with Sorbet
|
63
|
+
<p>Mangrove provides type utility to use with Sorbet. use <code>rubocop-mangrove</code> to statically check rescuing ControlSignal is done</p>
|
64
64
|
|
65
65
|
<p>You can do something like this with the gem.</p>
|
66
66
|
|
67
|
-
<p>use ‘rubocop-mangrove“ to statically check rescuing ControlSignal is done</p>
|
68
|
-
|
69
67
|
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>TransposeExample</span>
|
70
68
|
<span class='id identifier rubyid_extend'>extend</span> <span class='const'>T</span><span class='op'>::</span><span class='const'>Sig</span>
|
71
69
|
|
@@ -89,6 +87,84 @@
|
|
89
87
|
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>TransposeExample</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_divide_arguments_by_3'>divide_arguments_by_3</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='int'>3</span><span class='comma'>,</span> <span class='int'>6</span><span class='comma'>,</span> <span class='int'>9</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result/Ok.html" title="Mangrove::Result::Ok (class)">Ok</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Mangrove/Result/Ok.html#initialize-instance_method" title="Mangrove::Result::Ok#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='comma'>,</span> <span class='int'>3</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
90
88
|
</code></pre>
|
91
89
|
|
90
|
+
<p>or like this.</p>
|
91
|
+
|
92
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>MyController</span>
|
93
|
+
<span class='id identifier rubyid_extend'>extend</span> <span class='const'>T</span><span class='op'>::</span><span class='const'>Sig</span>
|
94
|
+
|
95
|
+
<span class='id identifier rubyid_sig'>sig</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_params'>params</span><span class='lparen'>(</span><span class='label'>input:</span> <span class='const'>String</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
96
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
|
97
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='const'>MyService</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
|
98
|
+
|
99
|
+
<span class='kw'>case</span> <span class='id identifier rubyid_result'>result</span>
|
100
|
+
<span class='kw'>when</span> <span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result/Ok.html" title="Mangrove::Result::Ok (class)">Ok</a></span></span>
|
101
|
+
<span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_ok_inner'>ok_inner</span>
|
102
|
+
<span class='kw'>when</span> <span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result/Err.html" title="Mangrove::Result::Err (class)">Err</a></span></span>
|
103
|
+
<span class='id identifier rubyid_error'>error</span> <span class='op'>=</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_err_inner'>err_inner</span>
|
104
|
+
|
105
|
+
<span class='kw'>case</span> <span class='id identifier rubyid_error'>error</span>
|
106
|
+
<span class='kw'>when</span> <span class='const'>MyService</span><span class='op'>::</span><span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E1</span>
|
107
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>e1: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_error'>error</span><span class='period'>.</span><span class='id identifier rubyid_inner'>inner</span><span class='period'>.</span><span class='id identifier rubyid_msg'>msg</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
108
|
+
<span class='kw'>when</span> <span class='const'>MyService</span><span class='op'>::</span><span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E2</span>
|
109
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>e2: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_error'>error</span><span class='period'>.</span><span class='id identifier rubyid_inner'>inner</span><span class='period'>.</span><span class='id identifier rubyid_msg'>msg</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
110
|
+
<span class='kw'>when</span> <span class='const'>MyService</span><span class='op'>::</span><span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>Other</span>
|
111
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>other: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_error'>error</span><span class='period'>.</span><span class='id identifier rubyid_inner'>inner</span><span class='period'>.</span><span class='id identifier rubyid_msg'>msg</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
112
|
+
<span class='kw'>else</span> <span class='const'>T</span><span class='period'>.</span><span class='id identifier rubyid_absurd'>absurd</span><span class='lparen'>(</span><span class='id identifier rubyid_error'>error</span><span class='rparen'>)</span>
|
113
|
+
<span class='kw'>end</span>
|
114
|
+
<span class='kw'>end</span>
|
115
|
+
<span class='kw'>end</span>
|
116
|
+
<span class='kw'>end</span>
|
117
|
+
|
118
|
+
<span class='kw'>class</span> <span class='const'>MyService</span>
|
119
|
+
<span class='id identifier rubyid_extend'>extend</span> <span class='const'>T</span><span class='op'>::</span><span class='const'>Sig</span>
|
120
|
+
<span class='id identifier rubyid_extend'>extend</span> <span class='const'>T</span><span class='op'>::</span><span class='const'>Generic</span>
|
121
|
+
|
122
|
+
<span class='id identifier rubyid_include'>include</span> <span class='const'>Kernel</span>
|
123
|
+
|
124
|
+
<span class='const'>E</span> <span class='op'>=</span> <span class='id identifier rubyid_type_member'>type_member</span> <span class='lbrace'>{</span> <span class='lbrace'>{</span> <span class='label'>upper:</span> <span class='const'>MyServiceError</span> <span class='rbrace'>}</span> <span class='rbrace'>}</span>
|
125
|
+
|
126
|
+
<span class='id identifier rubyid_sig'>sig</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_params'>params</span><span class='lparen'>(</span><span class='label'>input:</span> <span class='const'>String</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='lbracket'>[</span><span class='const'>String</span><span class='comma'>,</span> <span class='const'>MyServiceError</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
127
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
|
128
|
+
<span class='id identifier rubyid_input'>input</span>
|
129
|
+
<span class='period'>.</span><span class='id identifier rubyid_safe_to_i'>safe_to_i</span>
|
130
|
+
<span class='period'>.</span><span class='id identifier rubyid_map_err_wt'>map_err_wt</span><span class='lparen'>(</span><span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>Other</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_e'>e</span><span class='op'>|</span>
|
131
|
+
<span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>Other</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>MyAppError</span><span class='op'>::</span><span class='const'>Other</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_e'>e</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_as_my_service_error'>as_my_service_error</span>
|
132
|
+
<span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_and_then_wt'>and_then_wt</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_num'>num</span><span class='op'>|</span>
|
133
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_num'>num</span> <span class='op'><</span> <span class='int'>1</span>
|
134
|
+
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='period'>.</span><span class='id identifier rubyid_err'><span class='object_link'><a href="Mangrove/Result.html#err-class_method" title="Mangrove::Result.err (method)">err</a></span></span><span class='lparen'>(</span><span class='const'>String</span><span class='comma'>,</span> <span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E1</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>MyAppError</span><span class='op'>::</span><span class='const'>E1</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>num < 1</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_as_my_service_error'>as_my_service_error</span><span class='rparen'>)</span>
|
135
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_num'>num</span> <span class='op'><</span> <span class='int'>3</span>
|
136
|
+
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span>
|
137
|
+
<span class='period'>.</span><span class='id identifier rubyid_ok'>ok</span><span class='lparen'>(</span><span class='id identifier rubyid_num'>num</span><span class='comma'>,</span> <span class='const'>String</span><span class='rparen'>)</span>
|
138
|
+
<span class='period'>.</span><span class='id identifier rubyid_and_then_wt'>and_then_wt</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span>
|
139
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_n'>n</span> <span class='op'><</span> <span class='int'>2</span>
|
140
|
+
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='period'>.</span><span class='id identifier rubyid_ok'><span class='object_link'><a href="Mangrove/Result.html#ok-class_method" title="Mangrove::Result.ok (method)">ok</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>`</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_content'>` < 2</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='const'>String</span><span class='rparen'>)</span>
|
141
|
+
<span class='kw'>else</span>
|
142
|
+
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='period'>.</span><span class='id identifier rubyid_err'><span class='object_link'><a href="Mangrove/Result.html#err-class_method" title="Mangrove::Result.err (method)">err</a></span></span><span class='lparen'>(</span><span class='const'>String</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>not `</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_content'>` < 2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
143
|
+
<span class='kw'>end</span>
|
144
|
+
<span class='rbrace'>}</span>
|
145
|
+
<span class='period'>.</span><span class='id identifier rubyid_map_err_wt'>map_err_wt</span><span class='lparen'>(</span><span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E1</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_e'>e</span><span class='op'>|</span>
|
146
|
+
<span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E1</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>MyAppError</span><span class='op'>::</span><span class='const'>E1</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>mapping to E1 </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_e'>e</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_as_my_service_error'>as_my_service_error</span>
|
147
|
+
<span class='rbrace'>}</span>
|
148
|
+
<span class='period'>.</span><span class='id identifier rubyid_map_ok'>map_ok</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_str'>str</span><span class='op'>|</span>
|
149
|
+
<span class='lbrace'>{</span>
|
150
|
+
<span class='label'>my_key:</span> <span class='id identifier rubyid_str'>str</span>
|
151
|
+
<span class='rbrace'>}</span>
|
152
|
+
<span class='rbrace'>}</span>
|
153
|
+
<span class='period'>.</span><span class='id identifier rubyid_map_ok'>map_ok</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:to_s</span><span class='rparen'>)</span>
|
154
|
+
<span class='kw'>else</span>
|
155
|
+
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='period'>.</span><span class='id identifier rubyid_err'><span class='object_link'><a href="Mangrove/Result.html#err-class_method" title="Mangrove::Result.err (method)">err</a></span></span><span class='lparen'>(</span><span class='const'>String</span><span class='comma'>,</span> <span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E2</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>MyAppError</span><span class='op'>::</span><span class='const'>E2</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_as_my_service_error'>as_my_service_error</span><span class='rparen'>)</span>
|
156
|
+
<span class='kw'>end</span>
|
157
|
+
<span class='rbrace'>}</span>
|
158
|
+
<span class='kw'>end</span>
|
159
|
+
<span class='kw'>end</span>
|
160
|
+
|
161
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>MyController</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>e1: num < 1</span><span class='tstring_end'>"</span></span>
|
162
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>MyController</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>1</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>{:my_key=>\"`1` < 2\"}</span><span class='tstring_end'>"</span></span>
|
163
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>MyController</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>e1: mapping to E1 not `2` < 2</span><span class='tstring_end'>"</span></span>
|
164
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>MyController</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>3</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>e2: e2</span><span class='tstring_end'>"</span></span>
|
165
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>MyController</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>invalid</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>other: invalid value for Integer(): \"invalid\"</span><span class='tstring_end'>"</span></span>
|
166
|
+
</code></pre>
|
167
|
+
|
92
168
|
<p>Other examples are available at href="https://github.com/kazzix14/mangrove/tree/main/spec"></a>.</p>
|
93
169
|
|
94
170
|
<h2 id="label-Features">Features</h2>
|
@@ -113,7 +189,7 @@
|
|
113
189
|
|
114
190
|
<h2 id="label-Usage">Usage</h2>
|
115
191
|
|
116
|
-
<p
|
192
|
+
<p><a href="https://kazzix14.github.io/mangrove/">Documentation is available here</a>. For more concrete examples, see href="https://github.com/kazzix14/mangrove/tree/main/spec"></a>.</p>
|
117
193
|
|
118
194
|
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='lbracket'>[</span><span class='const'>OkType</span><span class='comma'>,</span> <span class='const'>ErrType</span><span class='rbracket'>]</span>
|
119
195
|
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result/Ok.html" title="Mangrove::Result::Ok (class)">Ok</a></span></span><span class='lbracket'>[</span><span class='const'>OkType</span><span class='comma'>,</span> <span class='const'>ErrType</span><span class='rbracket'>]</span>
|
@@ -126,13 +202,9 @@
|
|
126
202
|
<span class='id identifier rubyid_my_err'>my_err</span> <span class='op'>=</span> <span class='const'>Result</span><span class='op'>::</span><span class='const'>Err</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>my err</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
127
203
|
<span class='id identifier rubyid_my_some'>my_some</span> <span class='op'>=</span> <span class='const'>Option</span><span class='op'>::</span><span class='const'>Some</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>1234</span><span class='rparen'>)</span>
|
128
204
|
<span class='id identifier rubyid_my_none'>my_none</span> <span class='op'>=</span> <span class='const'>Option</span><span class='op'>::</span><span class='const'>None</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
129
|
-
|
130
|
-
<span class='comment'># 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.
|
131
|
-
</span><span class='comment'># https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator
|
132
|
-
</span><span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/ControlFlow.html" title="Mangrove::ControlFlow (module)">ControlFlow</a></span></span><span class='op'>::</span><span class='const'>Handler</span>
|
133
205
|
</code></pre>
|
134
206
|
|
135
|
-
<h2 id="label-Commands">Commands</h2>
|
207
|
+
<h2 id="label-Commands+for+Development">Commands for Development</h2>
|
136
208
|
|
137
209
|
<pre class="code ruby"><code class="ruby">git config core.hooksPath hooks
|
138
210
|
bundle exec tapioca init
|
@@ -162,7 +234,7 @@ rake release
|
|
162
234
|
</div></div>
|
163
235
|
|
164
236
|
<div id="footer">
|
165
|
-
Generated on
|
237
|
+
Generated on Wed Nov 1 14:25:08 2023 by
|
166
238
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
167
239
|
0.9.34 (ruby-3.2.2).
|
168
240
|
</div>
|
data/docs/index.html
CHANGED
@@ -60,12 +60,10 @@
|
|
60
60
|
<div id="content"><div id='filecontents'>
|
61
61
|
<h1 id="label-Mangrove">Mangrove</h1>
|
62
62
|
|
63
|
-
<p>Mangrove provides type utility to use with Sorbet
|
63
|
+
<p>Mangrove provides type utility to use with Sorbet. use <code>rubocop-mangrove</code> to statically check rescuing ControlSignal is done</p>
|
64
64
|
|
65
65
|
<p>You can do something like this with the gem.</p>
|
66
66
|
|
67
|
-
<p>use ‘rubocop-mangrove“ to statically check rescuing ControlSignal is done</p>
|
68
|
-
|
69
67
|
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>TransposeExample</span>
|
70
68
|
<span class='id identifier rubyid_extend'>extend</span> <span class='const'>T</span><span class='op'>::</span><span class='const'>Sig</span>
|
71
69
|
|
@@ -89,6 +87,84 @@
|
|
89
87
|
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>TransposeExample</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_divide_arguments_by_3'>divide_arguments_by_3</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='int'>3</span><span class='comma'>,</span> <span class='int'>6</span><span class='comma'>,</span> <span class='int'>9</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result/Ok.html" title="Mangrove::Result::Ok (class)">Ok</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Mangrove/Result/Ok.html#initialize-instance_method" title="Mangrove::Result::Ok#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='comma'>,</span> <span class='int'>3</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
90
88
|
</code></pre>
|
91
89
|
|
90
|
+
<p>or like this.</p>
|
91
|
+
|
92
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>MyController</span>
|
93
|
+
<span class='id identifier rubyid_extend'>extend</span> <span class='const'>T</span><span class='op'>::</span><span class='const'>Sig</span>
|
94
|
+
|
95
|
+
<span class='id identifier rubyid_sig'>sig</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_params'>params</span><span class='lparen'>(</span><span class='label'>input:</span> <span class='const'>String</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
96
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
|
97
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='const'>MyService</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
|
98
|
+
|
99
|
+
<span class='kw'>case</span> <span class='id identifier rubyid_result'>result</span>
|
100
|
+
<span class='kw'>when</span> <span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result/Ok.html" title="Mangrove::Result::Ok (class)">Ok</a></span></span>
|
101
|
+
<span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_ok_inner'>ok_inner</span>
|
102
|
+
<span class='kw'>when</span> <span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result/Err.html" title="Mangrove::Result::Err (class)">Err</a></span></span>
|
103
|
+
<span class='id identifier rubyid_error'>error</span> <span class='op'>=</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_err_inner'>err_inner</span>
|
104
|
+
|
105
|
+
<span class='kw'>case</span> <span class='id identifier rubyid_error'>error</span>
|
106
|
+
<span class='kw'>when</span> <span class='const'>MyService</span><span class='op'>::</span><span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E1</span>
|
107
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>e1: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_error'>error</span><span class='period'>.</span><span class='id identifier rubyid_inner'>inner</span><span class='period'>.</span><span class='id identifier rubyid_msg'>msg</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
108
|
+
<span class='kw'>when</span> <span class='const'>MyService</span><span class='op'>::</span><span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E2</span>
|
109
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>e2: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_error'>error</span><span class='period'>.</span><span class='id identifier rubyid_inner'>inner</span><span class='period'>.</span><span class='id identifier rubyid_msg'>msg</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
110
|
+
<span class='kw'>when</span> <span class='const'>MyService</span><span class='op'>::</span><span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>Other</span>
|
111
|
+
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>other: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_error'>error</span><span class='period'>.</span><span class='id identifier rubyid_inner'>inner</span><span class='period'>.</span><span class='id identifier rubyid_msg'>msg</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
112
|
+
<span class='kw'>else</span> <span class='const'>T</span><span class='period'>.</span><span class='id identifier rubyid_absurd'>absurd</span><span class='lparen'>(</span><span class='id identifier rubyid_error'>error</span><span class='rparen'>)</span>
|
113
|
+
<span class='kw'>end</span>
|
114
|
+
<span class='kw'>end</span>
|
115
|
+
<span class='kw'>end</span>
|
116
|
+
<span class='kw'>end</span>
|
117
|
+
|
118
|
+
<span class='kw'>class</span> <span class='const'>MyService</span>
|
119
|
+
<span class='id identifier rubyid_extend'>extend</span> <span class='const'>T</span><span class='op'>::</span><span class='const'>Sig</span>
|
120
|
+
<span class='id identifier rubyid_extend'>extend</span> <span class='const'>T</span><span class='op'>::</span><span class='const'>Generic</span>
|
121
|
+
|
122
|
+
<span class='id identifier rubyid_include'>include</span> <span class='const'>Kernel</span>
|
123
|
+
|
124
|
+
<span class='const'>E</span> <span class='op'>=</span> <span class='id identifier rubyid_type_member'>type_member</span> <span class='lbrace'>{</span> <span class='lbrace'>{</span> <span class='label'>upper:</span> <span class='const'>MyServiceError</span> <span class='rbrace'>}</span> <span class='rbrace'>}</span>
|
125
|
+
|
126
|
+
<span class='id identifier rubyid_sig'>sig</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_params'>params</span><span class='lparen'>(</span><span class='label'>input:</span> <span class='const'>String</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='lbracket'>[</span><span class='const'>String</span><span class='comma'>,</span> <span class='const'>MyServiceError</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
127
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='id identifier rubyid_input'>input</span><span class='rparen'>)</span>
|
128
|
+
<span class='id identifier rubyid_input'>input</span>
|
129
|
+
<span class='period'>.</span><span class='id identifier rubyid_safe_to_i'>safe_to_i</span>
|
130
|
+
<span class='period'>.</span><span class='id identifier rubyid_map_err_wt'>map_err_wt</span><span class='lparen'>(</span><span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>Other</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_e'>e</span><span class='op'>|</span>
|
131
|
+
<span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>Other</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>MyAppError</span><span class='op'>::</span><span class='const'>Other</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_e'>e</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_as_my_service_error'>as_my_service_error</span>
|
132
|
+
<span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_and_then_wt'>and_then_wt</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_num'>num</span><span class='op'>|</span>
|
133
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_num'>num</span> <span class='op'><</span> <span class='int'>1</span>
|
134
|
+
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='period'>.</span><span class='id identifier rubyid_err'><span class='object_link'><a href="Mangrove/Result.html#err-class_method" title="Mangrove::Result.err (method)">err</a></span></span><span class='lparen'>(</span><span class='const'>String</span><span class='comma'>,</span> <span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E1</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>MyAppError</span><span class='op'>::</span><span class='const'>E1</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>num < 1</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_as_my_service_error'>as_my_service_error</span><span class='rparen'>)</span>
|
135
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_num'>num</span> <span class='op'><</span> <span class='int'>3</span>
|
136
|
+
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span>
|
137
|
+
<span class='period'>.</span><span class='id identifier rubyid_ok'>ok</span><span class='lparen'>(</span><span class='id identifier rubyid_num'>num</span><span class='comma'>,</span> <span class='const'>String</span><span class='rparen'>)</span>
|
138
|
+
<span class='period'>.</span><span class='id identifier rubyid_and_then_wt'>and_then_wt</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span>
|
139
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_n'>n</span> <span class='op'><</span> <span class='int'>2</span>
|
140
|
+
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='period'>.</span><span class='id identifier rubyid_ok'><span class='object_link'><a href="Mangrove/Result.html#ok-class_method" title="Mangrove::Result.ok (method)">ok</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>`</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_content'>` < 2</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='const'>String</span><span class='rparen'>)</span>
|
141
|
+
<span class='kw'>else</span>
|
142
|
+
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='period'>.</span><span class='id identifier rubyid_err'><span class='object_link'><a href="Mangrove/Result.html#err-class_method" title="Mangrove::Result.err (method)">err</a></span></span><span class='lparen'>(</span><span class='const'>String</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>not `</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_content'>` < 2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
143
|
+
<span class='kw'>end</span>
|
144
|
+
<span class='rbrace'>}</span>
|
145
|
+
<span class='period'>.</span><span class='id identifier rubyid_map_err_wt'>map_err_wt</span><span class='lparen'>(</span><span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E1</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_e'>e</span><span class='op'>|</span>
|
146
|
+
<span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E1</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>MyAppError</span><span class='op'>::</span><span class='const'>E1</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>mapping to E1 </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_e'>e</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_as_my_service_error'>as_my_service_error</span>
|
147
|
+
<span class='rbrace'>}</span>
|
148
|
+
<span class='period'>.</span><span class='id identifier rubyid_map_ok'>map_ok</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_str'>str</span><span class='op'>|</span>
|
149
|
+
<span class='lbrace'>{</span>
|
150
|
+
<span class='label'>my_key:</span> <span class='id identifier rubyid_str'>str</span>
|
151
|
+
<span class='rbrace'>}</span>
|
152
|
+
<span class='rbrace'>}</span>
|
153
|
+
<span class='period'>.</span><span class='id identifier rubyid_map_ok'>map_ok</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:to_s</span><span class='rparen'>)</span>
|
154
|
+
<span class='kw'>else</span>
|
155
|
+
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='period'>.</span><span class='id identifier rubyid_err'><span class='object_link'><a href="Mangrove/Result.html#err-class_method" title="Mangrove::Result.err (method)">err</a></span></span><span class='lparen'>(</span><span class='const'>String</span><span class='comma'>,</span> <span class='const'>MyServiceError</span><span class='op'>::</span><span class='const'>E2</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>MyAppError</span><span class='op'>::</span><span class='const'>E2</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_as_my_service_error'>as_my_service_error</span><span class='rparen'>)</span>
|
156
|
+
<span class='kw'>end</span>
|
157
|
+
<span class='rbrace'>}</span>
|
158
|
+
<span class='kw'>end</span>
|
159
|
+
<span class='kw'>end</span>
|
160
|
+
|
161
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>MyController</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>e1: num < 1</span><span class='tstring_end'>"</span></span>
|
162
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>MyController</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>1</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>{:my_key=>\"`1` < 2\"}</span><span class='tstring_end'>"</span></span>
|
163
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>MyController</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>e1: mapping to E1 not `2` < 2</span><span class='tstring_end'>"</span></span>
|
164
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>MyController</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>3</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>e2: e2</span><span class='tstring_end'>"</span></span>
|
165
|
+
<span class='id identifier rubyid_expect'>expect</span><span class='lparen'>(</span><span class='const'>MyController</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>invalid</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_eq'>eq</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>other: invalid value for Integer(): \"invalid\"</span><span class='tstring_end'>"</span></span>
|
166
|
+
</code></pre>
|
167
|
+
|
92
168
|
<p>Other examples are available at href="https://github.com/kazzix14/mangrove/tree/main/spec"></a>.</p>
|
93
169
|
|
94
170
|
<h2 id="label-Features">Features</h2>
|
@@ -113,7 +189,7 @@
|
|
113
189
|
|
114
190
|
<h2 id="label-Usage">Usage</h2>
|
115
191
|
|
116
|
-
<p
|
192
|
+
<p><a href="https://kazzix14.github.io/mangrove/">Documentation is available here</a>. For more concrete examples, see href="https://github.com/kazzix14/mangrove/tree/main/spec"></a>.</p>
|
117
193
|
|
118
194
|
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='lbracket'>[</span><span class='const'>OkType</span><span class='comma'>,</span> <span class='const'>ErrType</span><span class='rbracket'>]</span>
|
119
195
|
<span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result.html" title="Mangrove::Result (module)">Result</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/Result/Ok.html" title="Mangrove::Result::Ok (class)">Ok</a></span></span><span class='lbracket'>[</span><span class='const'>OkType</span><span class='comma'>,</span> <span class='const'>ErrType</span><span class='rbracket'>]</span>
|
@@ -126,13 +202,9 @@
|
|
126
202
|
<span class='id identifier rubyid_my_err'>my_err</span> <span class='op'>=</span> <span class='const'>Result</span><span class='op'>::</span><span class='const'>Err</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>my err</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
127
203
|
<span class='id identifier rubyid_my_some'>my_some</span> <span class='op'>=</span> <span class='const'>Option</span><span class='op'>::</span><span class='const'>Some</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>1234</span><span class='rparen'>)</span>
|
128
204
|
<span class='id identifier rubyid_my_none'>my_none</span> <span class='op'>=</span> <span class='const'>Option</span><span class='op'>::</span><span class='const'>None</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
129
|
-
|
130
|
-
<span class='comment'># 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.
|
131
|
-
</span><span class='comment'># https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator
|
132
|
-
</span><span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="Mangrove.html" title="Mangrove (module)">Mangrove</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mangrove/ControlFlow.html" title="Mangrove::ControlFlow (module)">ControlFlow</a></span></span><span class='op'>::</span><span class='const'>Handler</span>
|
133
205
|
</code></pre>
|
134
206
|
|
135
|
-
<h2 id="label-Commands">Commands</h2>
|
207
|
+
<h2 id="label-Commands+for+Development">Commands for Development</h2>
|
136
208
|
|
137
209
|
<pre class="code ruby"><code class="ruby">git config core.hooksPath hooks
|
138
210
|
bundle exec tapioca init
|
@@ -162,7 +234,7 @@ rake release
|
|
162
234
|
</div></div>
|
163
235
|
|
164
236
|
<div id="footer">
|
165
|
-
Generated on
|
237
|
+
Generated on Wed Nov 1 14:25:07 2023 by
|
166
238
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
167
239
|
0.9.34 (ruby-3.2.2).
|
168
240
|
</div>
|
@@ -100,7 +100,7 @@
|
|
100
100
|
</div>
|
101
101
|
|
102
102
|
<div id="footer">
|
103
|
-
Generated on
|
103
|
+
Generated on Wed Nov 1 14:25:08 2023 by
|
104
104
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
105
|
0.9.34 (ruby-3.2.2).
|
106
106
|
</div>
|
data/lib/mangrove/result.rb
CHANGED
@@ -15,8 +15,8 @@ module Mangrove
|
|
15
15
|
sealed!
|
16
16
|
interface!
|
17
17
|
|
18
|
-
OkType = type_member
|
19
|
-
ErrType = type_member
|
18
|
+
OkType = type_member
|
19
|
+
ErrType = type_member
|
20
20
|
|
21
21
|
sig { abstract.params(other: BasicObject).returns(T::Boolean) }
|
22
22
|
def ==(other); end
|
@@ -33,7 +33,7 @@ module Mangrove
|
|
33
33
|
sig { abstract.params(message: String).returns(OkType) }
|
34
34
|
def expect!(message); end
|
35
35
|
|
36
|
-
sig { abstract.params(block: T.proc.returns(T.
|
36
|
+
sig { abstract.type_parameters(:E).params(block: T.proc.returns(T.type_parameter(:E))).returns(OkType) }
|
37
37
|
def expect_with!(&block); end
|
38
38
|
|
39
39
|
sig { abstract.type_parameters(:NewOkType, :NewErrType).params(block: T.proc.params(this: Result[OkType, ErrType]).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]) }
|
@@ -54,30 +54,30 @@ module Mangrove
|
|
54
54
|
sig { abstract.type_parameters(:NewErrType).params(_t_new_err: T::Class[T.type_parameter(:NewErrType)], block: T.proc.params(this: ErrType).returns(T.type_parameter(:NewErrType))).returns(Result[OkType, T.type_parameter(:NewErrType)]) }
|
55
55
|
def map_err_wt(_t_new_err, &block); end
|
56
56
|
|
57
|
-
sig { abstract.type_parameters(:NewOkType).params(other: Result[T.type_parameter(:NewOkType),
|
57
|
+
sig { abstract.type_parameters(:NewOkType).params(other: Result[T.type_parameter(:NewOkType), ErrType]).returns(Result[T.type_parameter(:NewOkType), ErrType]) }
|
58
58
|
def and(other); end
|
59
59
|
|
60
|
-
sig { abstract.type_parameters(:NewOkType).params(block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType),
|
60
|
+
sig { abstract.type_parameters(:NewOkType).params(block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType), ErrType])).returns(Result[T.type_parameter(:NewOkType), ErrType]) }
|
61
61
|
def and_then(&block); end
|
62
62
|
|
63
|
-
sig { abstract.type_parameters(:NewOkType).params(_t_new_ok: T::Class[T.type_parameter(:NewOkType)], block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType),
|
63
|
+
sig { abstract.type_parameters(:NewOkType).params(_t_new_ok: T::Class[T.type_parameter(:NewOkType)], block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType), ErrType])).returns(Result[T.type_parameter(:NewOkType), ErrType]) }
|
64
64
|
def and_then_wt(_t_new_ok, &block); end
|
65
65
|
|
66
|
-
sig { abstract.params(other: Result[
|
66
|
+
sig { abstract.params(other: Result[OkType, ErrType]).returns(Result[OkType, ErrType]) }
|
67
67
|
def or(other); end
|
68
68
|
|
69
|
-
sig { abstract.type_parameters(:NewErrType).params(block: T.proc.params(this: ErrType).returns(Result[
|
69
|
+
sig { abstract.type_parameters(:NewErrType).params(block: T.proc.params(this: ErrType).returns(Result[OkType, T.type_parameter(:NewErrType)])).returns(Result[OkType, T.type_parameter(:NewErrType)]) }
|
70
70
|
def or_else(&block); end
|
71
71
|
|
72
|
-
sig { abstract.type_parameters(:NewErrType).params(_t_new_err: T::Class[T.type_parameter(:NewErrType)], block: T.proc.params(this: ErrType).returns(Result[
|
72
|
+
sig { abstract.type_parameters(:NewErrType).params(_t_new_err: T::Class[T.type_parameter(:NewErrType)], block: T.proc.params(this: ErrType).returns(Result[OkType, T.type_parameter(:NewErrType)])).returns(Result[OkType, T.type_parameter(:NewErrType)]) }
|
73
73
|
def or_else_wt(_t_new_err, &block); end
|
74
74
|
|
75
75
|
class << self
|
76
76
|
extend T::Sig
|
77
77
|
extend T::Generic
|
78
78
|
|
79
|
-
OkType = type_member
|
80
|
-
ErrType = type_member
|
79
|
+
OkType = type_member
|
80
|
+
ErrType = type_member
|
81
81
|
|
82
82
|
sig { type_parameters(:T, :E).params(results: T::Enumerable[Result[T.type_parameter(:T), T.type_parameter(:E)]]).returns(Result[T::Enumerable[T.type_parameter(:T)], T::Enumerable[T.type_parameter(:E)]]) }
|
83
83
|
def from_results(results)
|
@@ -145,7 +145,7 @@ module Mangrove
|
|
145
145
|
@inner
|
146
146
|
end
|
147
147
|
|
148
|
-
sig { override.params(_block: T.proc.returns(T.
|
148
|
+
sig { override.type_parameters(:E).params(_block: T.proc.returns(T.type_parameter(:E))).returns(OkType) }
|
149
149
|
def expect_with!(&_block)
|
150
150
|
@inner
|
151
151
|
end
|
@@ -266,7 +266,7 @@ module Mangrove
|
|
266
266
|
raise Result::ControlSignal, message
|
267
267
|
end
|
268
268
|
|
269
|
-
sig { override.params(block: T.proc.returns(T.
|
269
|
+
sig { override.type_parameters(:E).params(block: T.proc.returns(T.type_parameter(:E))).returns(OkType) }
|
270
270
|
def expect_with!(&block)
|
271
271
|
raise Result::ControlSignal, block.call
|
272
272
|
end
|
data/lib/mangrove/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mangrove
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuma Murata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sorbet-runtime
|