Class: Mangrove::Result::Ok
- Inherits:
-
Object
- Object
- Mangrove::Result::Ok
show all
- Extended by:
- T::Generic, T::Helpers, T::Sig
- Includes:
- Mangrove::Result
- Defined in:
- lib/mangrove/result.rb
Constant Summary
collapse
- OkType =
type_member
- ErrType =
type_member
Instance Method Summary
collapse
-
#==(other) ⇒ Boolean
-
#and(other) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
-
#and_then(&block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
-
#and_then_wt(_t_new_ok, &block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
-
#err? ⇒ Boolean
-
#expect!(_message) ⇒ OkType
-
#expect_with!(&_block) ⇒ OkType
-
#initialize(inner) ⇒ void
constructor
-
#map(&block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]
-
#map_err(&_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
-
#map_err_wt(_t_new_err, &_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
Because sorbet deduct types from return values well.
-
#map_ok(&block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
-
#map_ok_wt(_t_new_ok, &block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
Because sorbet deduct types from return values well.
-
#map_wt(_t_new_ok, _t_new_err, &block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]
-
#ok? ⇒ Boolean
-
#ok_inner ⇒ OkType
-
#or(_other) ⇒ Result[OkType, ErrType]
-
#or_else(&_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
-
#or_else_wt(_t_new_err, &_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
-
#to_s ⇒ String
-
#unwrap! ⇒ OkType
err, err_wt, from_results, ok, ok_wt
Constructor Details
#initialize(inner) ⇒ void
127
128
129
|
# File 'lib/mangrove/result.rb', line 127
def initialize(inner)
@inner = inner
end
|
Instance Method Details
#==(other) ⇒ Boolean
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/mangrove/result.rb', line 132
def ==(other)
case other
when Result::Ok
other.instance_variable_get(:@inner) == @inner
when Result::Err
false
else false
end
end
|
#and(other) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
203
204
205
|
# File 'lib/mangrove/result.rb', line 203
def and(other)
other
end
|
#and_then(&block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
208
209
210
|
# File 'lib/mangrove/result.rb', line 208
def and_then(&block)
block.call(@inner)
end
|
#and_then_wt(_t_new_ok, &block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
213
214
215
|
# File 'lib/mangrove/result.rb', line 213
def and_then_wt(_t_new_ok, &block)
block.call(@inner)
end
|
#err? ⇒ Boolean
168
|
# File 'lib/mangrove/result.rb', line 168
def err? = false
|
#expect!(_message) ⇒ OkType
155
156
157
|
# File 'lib/mangrove/result.rb', line 155
def expect!(_message)
@inner
end
|
#expect_with!(&_block) ⇒ OkType
160
161
162
|
# File 'lib/mangrove/result.rb', line 160
def expect_with!(&_block)
@inner
end
|
#map(&block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]
171
172
173
|
# File 'lib/mangrove/result.rb', line 171
def map(&block)
block.call(self)
end
|
#map_err(&_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
192
193
194
|
# File 'lib/mangrove/result.rb', line 192
def map_err(&_block)
T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)])
end
|
#map_err_wt(_t_new_err, &_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
Because sorbet deduct types from return values well. This method takes a type of new inner values.
198
199
200
|
# File 'lib/mangrove/result.rb', line 198
def map_err_wt(_t_new_err, &_block)
T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)])
end
|
#map_ok(&block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
181
182
183
|
# File 'lib/mangrove/result.rb', line 181
def map_ok(&block)
Result::Ok[T.type_parameter(:NewOkType), ErrType].new(block.call(@inner))
end
|
#map_ok_wt(_t_new_ok, &block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
Because sorbet deduct types from return values well. This method takes a type of new inner values.
187
188
189
|
# File 'lib/mangrove/result.rb', line 187
def map_ok_wt(_t_new_ok, &block)
Result::Ok[T.type_parameter(:NewOkType), ErrType].new(block.call(@inner))
end
|
#map_wt(_t_new_ok, _t_new_err, &block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]
176
177
178
|
# File 'lib/mangrove/result.rb', line 176
def map_wt(_t_new_ok, _t_new_err, &block)
block.call(self)
end
|
#ok? ⇒ Boolean
165
|
# File 'lib/mangrove/result.rb', line 165
def ok? = true
|
145
146
147
|
# File 'lib/mangrove/result.rb', line 145
def ok_inner
@inner
end
|
218
219
220
|
# File 'lib/mangrove/result.rb', line 218
def or(_other)
self
end
|
#or_else(&_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
223
224
225
|
# File 'lib/mangrove/result.rb', line 223
def or_else(&_block)
T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)])
end
|
#or_else_wt(_t_new_err, &_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
228
229
230
|
# File 'lib/mangrove/result.rb', line 228
def or_else_wt(_t_new_err, &_block)
T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)])
end
|
#to_s ⇒ String
233
234
235
|
# File 'lib/mangrove/result.rb', line 233
def to_s
"#{super}: inner=`#{@inner}`"
end
|
150
151
152
|
# File 'lib/mangrove/result.rb', line 150
def unwrap!
@inner
end
|