mangrove 0.24.0 → 0.30.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 +32 -5
- data/lib/mangrove/result.rb +73 -64
- data/lib/mangrove/version.rb +1 -1
- data/rbi/mangrove.rbi +20 -0
- data/sorbet/rbi/annotations/rainbow.rbi +3 -3
- data/sorbet/rbi/gems/{diff-lcs@1.5.0.rbi → diff-lcs@1.5.1.rbi} +100 -48
- data/sorbet/rbi/gems/{io-console@0.6.0.rbi → io-console@0.7.2.rbi} +1 -0
- data/sorbet/rbi/gems/{json@2.6.3.rbi → json@2.7.2.rbi} +95 -74
- data/sorbet/rbi/gems/{parallel@1.23.0.rbi → parallel@1.24.0.rbi} +9 -1
- data/sorbet/rbi/gems/{parser@3.2.2.4.rbi → parser@3.3.2.0.rbi} +1267 -1282
- data/sorbet/rbi/gems/prism@0.29.0.rbi +37987 -0
- data/sorbet/rbi/gems/{psych@5.1.1.1.rbi → psych@5.1.2.rbi} +231 -267
- data/sorbet/rbi/gems/{racc@1.7.1.rbi → racc@1.8.0.rbi} +37 -36
- data/sorbet/rbi/gems/{rake@13.0.6.rbi → rake@13.2.1.rbi} +217 -73
- data/sorbet/rbi/gems/{rbi@0.1.3.rbi → rbi@0.1.13.rbi} +322 -166
- data/sorbet/rbi/gems/{rdoc@6.6.0.rbi → rdoc@6.7.0.rbi} +735 -685
- data/sorbet/rbi/gems/{regexp_parser@2.8.2.rbi → regexp_parser@2.9.2.rbi} +192 -169
- data/sorbet/rbi/gems/{reline@0.4.0.rbi → reline@0.5.8.rbi} +1 -0
- data/sorbet/rbi/gems/{rexml@3.2.6.rbi → rexml@3.2.8.rbi} +122 -109
- data/sorbet/rbi/gems/{rspec-core@3.12.2.rbi → rspec-core@3.13.0.rbi} +400 -300
- data/sorbet/rbi/gems/{rspec-expectations@3.12.3.rbi → rspec-expectations@3.13.0.rbi} +173 -119
- data/sorbet/rbi/gems/{rspec-mocks@3.12.6.rbi → rspec-mocks@3.13.1.rbi} +195 -160
- data/sorbet/rbi/gems/{rspec-support@3.12.1.rbi → rspec-support@3.13.1.rbi} +319 -298
- data/sorbet/rbi/gems/{rspec@3.12.0.rbi → rspec@3.13.0.rbi} +23 -22
- data/sorbet/rbi/gems/ruboclean@0.6.0.rbi +315 -0
- data/sorbet/rbi/gems/{rubocop-ast@1.29.0.rbi → rubocop-ast@1.31.3.rbi} +348 -285
- data/sorbet/rbi/gems/{rubocop-capybara@2.19.0.rbi → rubocop-capybara@2.20.0.rbi} +148 -65
- data/sorbet/rbi/gems/{rubocop-factory_bot@2.24.0.rbi → rubocop-factory_bot@2.25.1.rbi} +70 -20
- data/sorbet/rbi/gems/{rubocop-rspec@2.24.1.rbi → rubocop-rspec@2.30.0.rbi} +678 -389
- data/sorbet/rbi/gems/rubocop-rspec_rails@2.28.3.rbi +911 -0
- data/sorbet/rbi/gems/{rubocop@1.57.1.rbi → rubocop@1.64.1.rbi} +3225 -1915
- data/sorbet/rbi/gems/{ruby-lsp@0.12.0.rbi → ruby-lsp@0.17.2.rbi} +1 -0
- data/sorbet/rbi/gems/{spoom@1.2.4.rbi → spoom@1.3.2.rbi} +1057 -413
- data/sorbet/rbi/gems/strscan@3.1.0.rbi +9 -0
- data/sorbet/rbi/gems/{tapioca@0.11.10.rbi → tapioca@0.14.3.rbi} +268 -234
- data/sorbet/rbi/gems/{thor@1.3.0.rbi → thor@1.3.1.rbi} +57 -50
- data/sorbet/rbi/gems/{yard@0.9.34.rbi → yard@0.9.36.rbi} +154 -82
- metadata +38 -38
- data/sorbet/rbi/gems/base64@0.1.1.rbi +0 -172
- data/sorbet/rbi/gems/irb@1.9.0.rbi +0 -342
- data/sorbet/rbi/gems/prettier_print@1.2.1.rbi +0 -951
- data/sorbet/rbi/gems/prism@0.15.1.rbi +0 -23922
- data/sorbet/rbi/gems/ruboclean@0.4.0.rbi +0 -189
- data/sorbet/rbi/gems/syntax_tree@6.2.0.rbi +0 -23136
- /data/sorbet/rbi/gems/{stringio@3.0.9.rbi → stringio@3.1.0.rbi} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40399ea0d669ab22b7a7e87339f2805639fff8f3637d92cbd2053e808c2cfd51
|
4
|
+
data.tar.gz: 001bb14fdf77d56956f9a58bd516639c33db9dc5c7e49a866504d617a7f58541
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d2a3fc17f9add3fa5b58f7069782fcde4bf09c1237d3e8897e68f6809f1ed0e1548679475560e13c780d4c6f1eadede337c4e0fb9a552c32c4c6753d0fc38cc
|
7
|
+
data.tar.gz: 2e0b2daa053cb9e1116597f21f9eeebac38ae1b174313cca1f612a992983f4fe8d92e7243751664d3f3f8f1ed7b5a1d91843282ea503ff5dae85909ad0d8b471
|
data/README.md
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# Mangrove
|
2
|
-
Mangrove provides type utility to use with Sorbet.
|
3
2
|
|
4
3
|
Mangrove is a Ruby Gem designed to be the definitive toolkit for leveraging Sorbet's type system in Ruby applications. It's designed to offer a robust, statically-typed experience, focusing on solid types, a functional programming style, and an interface-driven approach.
|
5
4
|
|
6
|
-
Use `rubocop-mangrove` to statically check rescuing ControlSignal is done
|
7
|
-
|
8
5
|
- [Documentation](https://kazzix14.github.io/mangrove/docs/)
|
9
6
|
- [Coverage](https://kazzix14.github.io/mangrove/coverage/index.html#_AllFiles)
|
10
7
|
|
11
8
|
## Features
|
9
|
+
|
12
10
|
- Option Type
|
13
11
|
- Result Type
|
14
12
|
- Enums with inner types (ADTs)
|
@@ -36,9 +34,38 @@ my_ok = Result::Ok.new("my value")
|
|
36
34
|
my_err = Result::Err.new("my err")
|
37
35
|
my_some = Option::Some.new(1234)
|
38
36
|
my_none = Option::None.new
|
37
|
+
|
38
|
+
##############################
|
39
|
+
|
40
|
+
response = MyClient
|
41
|
+
.new
|
42
|
+
.and_then { |client| client.get_response() }
|
43
|
+
.and_then { |response| response.body }
|
44
|
+
|
45
|
+
case response
|
46
|
+
when Mangrove::Result::Ok
|
47
|
+
puts response.ok_inner
|
48
|
+
when Mangrove::Result::Err
|
49
|
+
puts response.err_inner
|
50
|
+
end
|
51
|
+
|
52
|
+
##############################
|
53
|
+
|
54
|
+
class MyEnum
|
55
|
+
extend Mangrove::Enum
|
56
|
+
|
57
|
+
variants do
|
58
|
+
variant VariantWithInteger, Integer
|
59
|
+
variant VariantWithString, String
|
60
|
+
variant VariantWithException, Exception
|
61
|
+
variant VariantWithTuple, [Integer, String]
|
62
|
+
variant VariantWithShape, { name: String, age: Integer }
|
63
|
+
end
|
64
|
+
end
|
39
65
|
```
|
40
66
|
|
41
67
|
## Commands for Development
|
68
|
+
|
42
69
|
```
|
43
70
|
git config core.hooksPath hooks
|
44
71
|
bundle install
|
@@ -50,9 +77,9 @@ bundle exec tapioca init
|
|
50
77
|
bundle exec rspec -f d
|
51
78
|
bundle exec rubocop -DESP
|
52
79
|
bundle exec srb typecheck
|
53
|
-
bundle exec spoom tc
|
80
|
+
bundle exec spoom srb tc
|
54
81
|
bundle exec ordinare --check
|
55
|
-
bundle exec ruboclean
|
82
|
+
bundle exec ruboclean --verify
|
56
83
|
bundle exec yardoc -o docs/ --plugin yard-sorbet
|
57
84
|
bundle exec yard server --reload --plugin yard-sorbet
|
58
85
|
rake build
|
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(:out)
|
19
|
+
ErrType = type_member(:out)
|
20
20
|
|
21
21
|
sig { abstract.params(other: BasicObject).returns(T::Boolean) }
|
22
22
|
def ==(other); end
|
@@ -51,7 +51,7 @@ module Mangrove
|
|
51
51
|
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)]) }
|
52
52
|
def map(&block); end
|
53
53
|
|
54
|
-
sig { abstract.type_parameters(:NewOkType, :NewErrType).params(_t_new_ok: T.type_parameter(:NewOkType), _t_new_err: T.type_parameter(:NewErrType), 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
|
+
sig { abstract.type_parameters(:NewOkType, :NewErrType).params(_t_new_ok: T::Class[T.type_parameter(:NewOkType)], _t_new_err: T::Class[T.type_parameter(:NewErrType)], 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)]) }
|
55
55
|
def map_wt(_t_new_ok, _t_new_err, &block); end
|
56
56
|
|
57
57
|
sig { abstract.type_parameters(:NewOkType).params(block: T.proc.params(this: OkType).returns(T.type_parameter(:NewOkType))).returns(Result[T.type_parameter(:NewOkType), ErrType]) }
|
@@ -66,44 +66,46 @@ module Mangrove
|
|
66
66
|
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)]) }
|
67
67
|
def map_err_wt(_t_new_err, &block); end
|
68
68
|
|
69
|
-
sig { abstract.type_parameters(:NewOkType).params(other: Result[T.type_parameter(:NewOkType),
|
69
|
+
sig { abstract.type_parameters(:NewOkType, :NewErrType).params(other: Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]).returns(T.any(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)], Result[T.type_parameter(:NewOkType), ErrType])) }
|
70
70
|
def and(other); end
|
71
71
|
|
72
|
-
sig { abstract.type_parameters(:NewOkType).params(block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType),
|
72
|
+
sig { abstract.type_parameters(:NewOkType, :NewErrType).params(block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(T.any(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)], Result[T.type_parameter(:NewOkType), ErrType])) }
|
73
73
|
def and_then(&block); end
|
74
74
|
|
75
|
-
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),
|
75
|
+
sig { abstract.type_parameters(:NewOkType, :NewErrType).params(_t_new_ok: T::Class[T.type_parameter(:NewOkType)], block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(T.any(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)], Result[T.type_parameter(:NewOkType), ErrType])) }
|
76
76
|
def and_then_wt(_t_new_ok, &block); end
|
77
77
|
|
78
78
|
sig {
|
79
79
|
abstract
|
80
|
+
.type_parameters(:NewErrType)
|
80
81
|
.params(
|
81
|
-
new_err_inner:
|
82
|
+
new_err_inner: T.type_parameter(:NewErrType),
|
82
83
|
condition: T.proc.params(inner: OkType).returns(T::Boolean)
|
83
84
|
)
|
84
85
|
.returns(
|
85
|
-
Result[OkType, ErrType]
|
86
|
+
T.any(Result[OkType, T.type_parameter(:NewErrType)], Result[OkType, ErrType])
|
86
87
|
)
|
87
88
|
}
|
88
89
|
def and_err_if(new_err_inner, &condition); end
|
89
90
|
|
90
|
-
sig { abstract.params(other: Result[
|
91
|
+
sig { abstract.type_parameters(:NewOkType, :NewErrType).params(other: Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]).returns(T.any(Result[OkType, T.type_parameter(:NewErrType)], Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])) }
|
91
92
|
def or(other); end
|
92
93
|
|
93
|
-
sig { abstract.type_parameters(:NewErrType).params(block: T.proc.params(this: ErrType).returns(Result[
|
94
|
+
sig { abstract.type_parameters(:NewOkType, :NewErrType).params(block: T.proc.params(this: ErrType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(T.any(Result[OkType, T.type_parameter(:NewErrType)], Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])) }
|
94
95
|
def or_else(&block); end
|
95
96
|
|
96
|
-
sig { abstract.type_parameters(:NewErrType).params(_t_new_err: T::Class[T.type_parameter(:NewErrType)], block: T.proc.params(this: ErrType).returns(Result[
|
97
|
+
sig { abstract.type_parameters(:NewOkType, :NewErrType).params(_t_new_err: T::Class[T.type_parameter(:NewErrType)], block: T.proc.params(this: ErrType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(T.any(Result[OkType, T.type_parameter(:NewErrType)], Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])) }
|
97
98
|
def or_else_wt(_t_new_err, &block); end
|
98
99
|
|
99
100
|
sig {
|
100
101
|
abstract
|
102
|
+
.type_parameters(:NewOkType)
|
101
103
|
.params(
|
102
|
-
new_ok_inner:
|
104
|
+
new_ok_inner: T.type_parameter(:NewOkType),
|
103
105
|
condition: T.proc.params(inner: ErrType).returns(T::Boolean)
|
104
106
|
)
|
105
107
|
.returns(
|
106
|
-
Result[OkType, ErrType]
|
108
|
+
T.any(Result[T.type_parameter(:NewOkType), ErrType], Result[OkType, ErrType])
|
107
109
|
)
|
108
110
|
}
|
109
111
|
def or_ok_if(new_ok_inner, &condition); end
|
@@ -121,31 +123,33 @@ module Mangrove
|
|
121
123
|
|
122
124
|
if errs.empty?
|
123
125
|
# This is safe as errs is empty.
|
124
|
-
Result::Ok[T::Enumerable[T.type_parameter(:T)]
|
126
|
+
Result::Ok[T::Enumerable[T.type_parameter(:T)]].new(results.map { |r| T.cast(r, Result::Ok[T.type_parameter(:T)]).ok_inner })
|
125
127
|
else
|
126
128
|
# This is safe as errs is results where err? is true
|
127
|
-
Result::Err[T::Enumerable[T.type_parameter(:
|
129
|
+
Result::Err[T::Enumerable[T.type_parameter(:E)]].new(errs.map { |r| T.cast(r, Result::Err[T.type_parameter(:E)]).err_inner })
|
128
130
|
end
|
129
131
|
end
|
130
132
|
|
131
|
-
sig { type_parameters(:OkType).params(inner: T.type_parameter(:OkType)).returns(Result::Ok[T.type_parameter(:OkType)
|
133
|
+
sig { type_parameters(:OkType).params(inner: T.type_parameter(:OkType)).returns(Result::Ok[T.type_parameter(:OkType)]) }
|
132
134
|
def ok(inner)
|
133
|
-
Result::Ok[T.type_parameter(:OkType)
|
135
|
+
Result::Ok[T.type_parameter(:OkType)].new(inner)
|
134
136
|
end
|
135
137
|
|
136
|
-
|
138
|
+
# @deprecated
|
139
|
+
sig { type_parameters(:OkType, :ErrType).params(inner: T.type_parameter(:OkType), _t_err: T::Class[T.type_parameter(:ErrType)]).returns(Result::Ok[T.type_parameter(:OkType)]) }
|
137
140
|
def ok_wt(inner, _t_err)
|
138
|
-
Result::Ok[T.type_parameter(:OkType)
|
141
|
+
Result::Ok[T.type_parameter(:OkType)].new(inner)
|
139
142
|
end
|
140
143
|
|
141
|
-
sig { type_parameters(:ErrType).params(inner: T.type_parameter(:ErrType)).returns(Result::Err[T.
|
144
|
+
sig { type_parameters(:ErrType).params(inner: T.type_parameter(:ErrType)).returns(Result::Err[T.type_parameter(:ErrType)]) }
|
142
145
|
def err(inner)
|
143
|
-
Result::Err[T.
|
146
|
+
Result::Err[T.type_parameter(:ErrType)].new(inner)
|
144
147
|
end
|
145
148
|
|
146
|
-
|
149
|
+
# @deprecated
|
150
|
+
sig { type_parameters(:OkType, :ErrType).params(_t_ok: T::Class[T.type_parameter(:OkType)], inner: T.type_parameter(:ErrType)).returns(Result::Err[T.type_parameter(:ErrType)]) }
|
147
151
|
def err_wt(_t_ok, inner)
|
148
|
-
Result::Err[T.type_parameter(:
|
152
|
+
Result::Err[T.type_parameter(:ErrType)].new(inner)
|
149
153
|
end
|
150
154
|
end
|
151
155
|
|
@@ -157,7 +161,7 @@ module Mangrove
|
|
157
161
|
include Result
|
158
162
|
|
159
163
|
OkType = type_member
|
160
|
-
ErrType = type_member
|
164
|
+
ErrType = type_member { { fixed: T.noreturn } }
|
161
165
|
|
162
166
|
sig { params(inner: OkType).void }
|
163
167
|
def initialize(inner)
|
@@ -225,89 +229,93 @@ module Mangrove
|
|
225
229
|
block.call(self)
|
226
230
|
end
|
227
231
|
|
228
|
-
sig { override.type_parameters(:NewOkType, :NewErrType).params(_t_new_ok: T.type_parameter(:NewOkType), _t_new_err: T.type_parameter(:NewErrType), 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)]) }
|
232
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(_t_new_ok: T::Class[T.type_parameter(:NewOkType)], _t_new_err: T::Class[T.type_parameter(:NewErrType)], 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)]) }
|
229
233
|
def map_wt(_t_new_ok, _t_new_err, &block)
|
230
234
|
block.call(self)
|
231
235
|
end
|
232
236
|
|
233
237
|
sig { override.type_parameters(:NewOkType).params(block: T.proc.params(this: OkType).returns(T.type_parameter(:NewOkType))).returns(Result[T.type_parameter(:NewOkType), ErrType]) }
|
234
238
|
def map_ok(&block)
|
235
|
-
Result::Ok[T.type_parameter(:NewOkType)
|
239
|
+
Result::Ok[T.type_parameter(:NewOkType)].new(block.call(@inner))
|
236
240
|
end
|
237
241
|
|
238
242
|
# Because sorbet does not deduct types from return values well. This method takes a type of new inner values.
|
239
243
|
sig { override.type_parameters(:NewOkType).params(_t_new_ok: T::Class[T.type_parameter(:NewOkType)], block: T.proc.params(this: OkType).returns(T.type_parameter(:NewOkType))).returns(Result[T.type_parameter(:NewOkType), ErrType]) }
|
240
244
|
def map_ok_wt(_t_new_ok, &block)
|
241
|
-
Result::Ok[T.type_parameter(:NewOkType)
|
245
|
+
Result::Ok[T.type_parameter(:NewOkType)].new(block.call(@inner))
|
242
246
|
end
|
243
247
|
|
244
248
|
sig { override.type_parameters(:NewErrType).params(_block: T.proc.params(this: ErrType).returns(T.type_parameter(:NewErrType))).returns(Result[OkType, T.type_parameter(:NewErrType)]) }
|
245
249
|
def map_err(&_block)
|
246
|
-
|
250
|
+
self
|
247
251
|
end
|
248
252
|
|
249
253
|
# Because sorbet does not deduct types from return values well. This method takes a type of new inner values.
|
250
254
|
sig { override.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)]) }
|
251
255
|
def map_err_wt(_t_new_err, &_block)
|
252
|
-
|
256
|
+
self
|
253
257
|
end
|
254
258
|
|
255
|
-
sig { override.type_parameters(:NewOkType).params(other: Result[T.type_parameter(:NewOkType),
|
259
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(other: Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]) }
|
256
260
|
def and(other)
|
257
261
|
other
|
258
262
|
end
|
259
263
|
|
260
|
-
sig { override.type_parameters(:NewOkType).params(block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType),
|
264
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]) }
|
261
265
|
def and_then(&block)
|
262
266
|
block.call(@inner)
|
263
267
|
end
|
264
268
|
|
265
|
-
|
269
|
+
# @deprecated
|
270
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(_t_new_ok: T::Class[T.type_parameter(:NewOkType)], block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]) }
|
266
271
|
def and_then_wt(_t_new_ok, &block)
|
267
272
|
block.call(@inner)
|
268
273
|
end
|
269
274
|
|
270
275
|
sig {
|
271
276
|
override
|
277
|
+
.type_parameters(:NewErrType)
|
272
278
|
.params(
|
273
|
-
new_err_inner:
|
279
|
+
new_err_inner: T.type_parameter(:NewErrType),
|
274
280
|
condition: T.proc.params(inner: OkType).returns(T::Boolean)
|
275
281
|
)
|
276
282
|
.returns(
|
277
|
-
Result[OkType,
|
283
|
+
Result[OkType, T.type_parameter(:NewErrType)]
|
278
284
|
)
|
279
285
|
}
|
280
286
|
def and_err_if(new_err_inner, &condition)
|
281
287
|
if condition.call(@inner)
|
282
|
-
Result::Err[
|
288
|
+
Result::Err[T.type_parameter(:NewErrType)].new(new_err_inner)
|
283
289
|
else
|
284
290
|
self
|
285
291
|
end
|
286
292
|
end
|
287
293
|
|
288
|
-
sig { override.params(_other: Result[
|
294
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(_other: Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]).returns(Result[OkType, T.type_parameter(:NewErrType)]) }
|
289
295
|
def or(_other)
|
290
296
|
self
|
291
297
|
end
|
292
298
|
|
293
|
-
sig { override.type_parameters(:NewErrType).params(_block: T.proc.params(this: ErrType).returns(Result[
|
299
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(_block: T.proc.params(this: ErrType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(Result[OkType, T.type_parameter(:NewErrType)]) }
|
294
300
|
def or_else(&_block)
|
295
|
-
|
301
|
+
self
|
296
302
|
end
|
297
303
|
|
298
|
-
|
304
|
+
# @deprecated
|
305
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(_t_new_err: T::Class[T.type_parameter(:NewErrType)], _block: T.proc.params(this: ErrType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(Result[OkType, T.type_parameter(:NewErrType)]) }
|
299
306
|
def or_else_wt(_t_new_err, &_block)
|
300
|
-
|
307
|
+
self
|
301
308
|
end
|
302
309
|
|
303
310
|
sig {
|
304
311
|
override
|
312
|
+
.type_parameters(:NewOkType)
|
305
313
|
.params(
|
306
|
-
_new_ok_inner:
|
314
|
+
_new_ok_inner: T.type_parameter(:NewOkType),
|
307
315
|
_condition: T.proc.params(inner: ErrType).returns(T::Boolean)
|
308
316
|
)
|
309
317
|
.returns(
|
310
|
-
Result
|
318
|
+
Result[OkType, ErrType]
|
311
319
|
)
|
312
320
|
}
|
313
321
|
def or_ok_if(_new_ok_inner, &_condition)
|
@@ -327,7 +335,7 @@ module Mangrove
|
|
327
335
|
|
328
336
|
include Result
|
329
337
|
|
330
|
-
OkType = type_member
|
338
|
+
OkType = type_member { { fixed: T.noreturn } }
|
331
339
|
ErrType = type_member
|
332
340
|
|
333
341
|
sig { params(inner: ErrType).void }
|
@@ -396,90 +404,91 @@ module Mangrove
|
|
396
404
|
block.call(self)
|
397
405
|
end
|
398
406
|
|
399
|
-
sig { override.type_parameters(:NewOkType, :NewErrType).params(_t_new_ok: T.type_parameter(:NewOkType), _t_new_err: T.type_parameter(:NewErrType), 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)]) }
|
407
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(_t_new_ok: T::Class[T.type_parameter(:NewOkType)], _t_new_err: T::Class[T.type_parameter(:NewErrType)], 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)]) }
|
400
408
|
def map_wt(_t_new_ok, _t_new_err, &block)
|
401
409
|
block.call(self)
|
402
410
|
end
|
403
411
|
|
404
412
|
sig { override.type_parameters(:NewOkType).params(_block: T.proc.params(this: OkType).returns(T.type_parameter(:NewOkType))).returns(Result[T.type_parameter(:NewOkType), ErrType]) }
|
405
413
|
def map_ok(&_block)
|
406
|
-
|
414
|
+
self
|
407
415
|
end
|
408
416
|
|
409
|
-
# Because sorbet does not deduct types from return values well. This method takes a type of new inner values.
|
410
417
|
sig { override.type_parameters(:NewOkType).params(_t_new_ok: T::Class[T.type_parameter(:NewOkType)], _block: T.proc.params(this: OkType).returns(T.type_parameter(:NewOkType))).returns(Result[T.type_parameter(:NewOkType), ErrType]) }
|
411
418
|
def map_ok_wt(_t_new_ok, &_block)
|
412
|
-
|
419
|
+
self
|
413
420
|
end
|
414
421
|
|
415
422
|
sig { override.type_parameters(:NewErrType).params(block: T.proc.params(this: ErrType).returns(T.type_parameter(:NewErrType))).returns(Result[OkType, T.type_parameter(:NewErrType)]) }
|
416
423
|
def map_err(&block)
|
417
|
-
Result::Err[
|
424
|
+
Result::Err[T.type_parameter(:NewErrType)].new(block.call(@inner))
|
418
425
|
end
|
419
426
|
|
420
|
-
# Because sorbet does not deduct types from return values well. This method takes a type of new inner values.
|
421
427
|
sig { override.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)]) }
|
422
428
|
def map_err_wt(_t_new_err, &block)
|
423
|
-
Result::Err[
|
429
|
+
Result::Err[T.type_parameter(:NewErrType)].new(block.call(@inner))
|
424
430
|
end
|
425
431
|
|
426
|
-
sig { override.type_parameters(:NewOkType).params(_other: Result[T.type_parameter(:NewOkType),
|
432
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(_other: Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]).returns(Result[T.type_parameter(:NewOkType), ErrType]) }
|
427
433
|
def and(_other)
|
428
|
-
|
434
|
+
self
|
429
435
|
end
|
430
436
|
|
431
|
-
sig { override.type_parameters(:NewOkType).params(_block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType),
|
437
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(_block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(Result[T.type_parameter(:NewOkType), ErrType]) }
|
432
438
|
def and_then(&_block)
|
433
|
-
|
439
|
+
self
|
434
440
|
end
|
435
441
|
|
436
|
-
|
442
|
+
# @deprecated
|
443
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(_t_new_ok: T::Class[T.type_parameter(:NewOkType)], _block: T.proc.params(this: OkType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(Result[T.type_parameter(:NewOkType), ErrType]) }
|
437
444
|
def and_then_wt(_t_new_ok, &_block)
|
438
|
-
|
445
|
+
self
|
439
446
|
end
|
440
447
|
|
441
448
|
sig {
|
442
449
|
override
|
450
|
+
.type_parameters(:NewErrType)
|
443
451
|
.params(
|
444
|
-
_new_err_inner:
|
452
|
+
_new_err_inner: T.type_parameter(:NewErrType),
|
445
453
|
_condition: T.proc.params(inner: OkType).returns(T::Boolean)
|
446
454
|
)
|
447
455
|
.returns(
|
448
|
-
Result
|
456
|
+
Result[OkType, ErrType]
|
449
457
|
)
|
450
458
|
}
|
451
459
|
def and_err_if(_new_err_inner, &_condition)
|
452
460
|
self
|
453
461
|
end
|
454
462
|
|
455
|
-
sig { override.params(other: Result[
|
463
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(other: Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]) }
|
456
464
|
def or(other)
|
457
465
|
other
|
458
466
|
end
|
459
467
|
|
460
|
-
sig { override.type_parameters(:NewErrType).params(block: T.proc.params(this: ErrType).returns(Result[
|
468
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(block: T.proc.params(this: ErrType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]) }
|
461
469
|
def or_else(&block)
|
462
470
|
block.call(@inner)
|
463
471
|
end
|
464
472
|
|
465
|
-
sig { override.type_parameters(:NewErrType).params(_t_new_err: T::Class[T.type_parameter(:NewErrType)], block: T.proc.params(this: ErrType).returns(Result[
|
473
|
+
sig { override.type_parameters(:NewOkType, :NewErrType).params(_t_new_err: T::Class[T.type_parameter(:NewErrType)], block: T.proc.params(this: ErrType).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)])).returns(Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]) }
|
466
474
|
def or_else_wt(_t_new_err, &block)
|
467
475
|
block.call(@inner)
|
468
476
|
end
|
469
477
|
|
470
478
|
sig {
|
471
479
|
override
|
480
|
+
.type_parameters(:NewOkType)
|
472
481
|
.params(
|
473
|
-
new_ok_inner:
|
482
|
+
new_ok_inner: T.type_parameter(:NewOkType),
|
474
483
|
condition: T.proc.params(inner: ErrType).returns(T::Boolean)
|
475
484
|
)
|
476
485
|
.returns(
|
477
|
-
Result[
|
486
|
+
Result[T.type_parameter(:NewOkType), ErrType]
|
478
487
|
)
|
479
488
|
}
|
480
489
|
def or_ok_if(new_ok_inner, &condition)
|
481
490
|
if condition.call(@inner)
|
482
|
-
Result::Ok[
|
491
|
+
Result::Ok[T.type_parameter(:NewOkType)].new(new_ok_inner)
|
483
492
|
else
|
484
493
|
self
|
485
494
|
end
|
data/lib/mangrove/version.rb
CHANGED
data/rbi/mangrove.rbi
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
3
|
+
module Mangrove
|
4
|
+
# Result is a type that represents either success (`Ok`) or failure (`Err`).
|
5
|
+
module Result
|
6
|
+
class Err
|
7
|
+
class << self
|
8
|
+
sig { type_parameters(:ErrType).params(inner: T.type_parameter(:ErrType)).returns(Mangrove::Result::Err[T.type_parameter(:ErrType)]) }
|
9
|
+
def new(inner); end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Ok
|
14
|
+
class << self
|
15
|
+
sig { type_parameters(:OkType).params(inner: T.type_parameter(:OkType)).returns(Mangrove::Result::Ok[T.type_parameter(:OkType)]) }
|
16
|
+
def new(inner); end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -60,14 +60,14 @@ module Rainbow
|
|
60
60
|
class X11Named < Rainbow::Color::RGB
|
61
61
|
include Rainbow::X11ColorNames
|
62
62
|
|
63
|
+
sig { params(ground: Symbol, name: Symbol).void }
|
64
|
+
def initialize(ground, name); end
|
65
|
+
|
63
66
|
sig { returns(T::Array[Symbol]) }
|
64
67
|
def self.color_names; end
|
65
68
|
|
66
69
|
sig { returns(String) }
|
67
70
|
def self.valid_names; end
|
68
|
-
|
69
|
-
sig { params(ground: Symbol, name: Symbol).void }
|
70
|
-
def initialize(ground, name); end
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|