Class: Mayak::Monads::Result::Success
- Inherits:
-
Object
- Object
- Mayak::Monads::Result::Success
show all
- Extended by:
- T::Generic, T::Helpers, T::Sig
- Includes:
- Mayak::Monads::Result
- Defined in:
- lib/mayak/monads/result.rb
Constant Summary
collapse
- FailureType =
type_member
- SuccessType =
type_member
Instance Method Summary
collapse
#==, #as, #failure_as, sequence
Constructor Details
#initialize(value) ⇒ Success
Returns a new instance of Success.
237
238
239
|
# File 'lib/mayak/monads/result.rb', line 237
def initialize(value)
@success_value = T.let(value, SuccessType)
end
|
Instance Method Details
#either(failure_branch, success_branch) ⇒ Object
342
343
344
|
# File 'lib/mayak/monads/result.rb', line 342
def either(failure_branch, success_branch)
success_branch.call(@success_value)
end
|
#failure? ⇒ Boolean
289
290
291
|
# File 'lib/mayak/monads/result.rb', line 289
def failure?
false
end
|
#failure_or(value) ⇒ Object
309
310
311
|
# File 'lib/mayak/monads/result.rb', line 309
def failure_or(value)
value
end
|
#filter_or(error, &blk) ⇒ Object
270
271
272
273
274
275
276
|
# File 'lib/mayak/monads/result.rb', line 270
def filter_or(error, &blk)
if blk.call(@success_value)
self
else
::Mayak::Monads::Result::Failure[T.any(FailureType, T.type_parameter(:NewFailure)), SuccessType].new(error)
end
end
|
#flat_map(&blk) ⇒ Object
260
261
262
|
# File 'lib/mayak/monads/result.rb', line 260
def flat_map(&blk)
blk.call(@success_value)
end
|
#flat_map_failure(&blk) ⇒ Object
381
382
383
384
385
386
|
# File 'lib/mayak/monads/result.rb', line 381
def flat_map_failure(&blk)
T.cast(
self,
Mayak::Monads::Result[T.type_parameter(:NewFailure), SuccessType]
)
end
|
#map(&blk) ⇒ Object
247
248
249
|
# File 'lib/mayak/monads/result.rb', line 247
def map(&blk)
Mayak::Monads::Result::Success.new(blk.call(@success_value))
end
|
#map_failure(&blk) ⇒ Object
365
366
367
368
369
370
|
# File 'lib/mayak/monads/result.rb', line 365
def map_failure(&blk)
T.cast(
self,
Mayak::Monads::Result[T.type_parameter(:NewFailure), SuccessType]
)
end
|
#recover(value) ⇒ Object
394
395
396
|
# File 'lib/mayak/monads/result.rb', line 394
def recover(value)
self
end
|
#recover_with(&blk) ⇒ Object
404
405
406
|
# File 'lib/mayak/monads/result.rb', line 404
def recover_with(&blk)
self
end
|
#recover_with_result(&blk) ⇒ Object
417
418
419
420
421
422
|
# File 'lib/mayak/monads/result.rb', line 417
def recover_with_result(&blk)
T.cast(
self,
Mayak::Monads::Result[T.type_parameter(:NewFailure), SuccessType]
)
end
|
#success ⇒ Object
279
280
281
|
# File 'lib/mayak/monads/result.rb', line 279
def success
@success_value
end
|
#success? ⇒ Boolean
284
285
286
|
# File 'lib/mayak/monads/result.rb', line 284
def success?
true
end
|
#success_or(value) ⇒ Object
299
300
301
|
# File 'lib/mayak/monads/result.rb', line 299
def success_or(value)
@success_value
end
|
#tee(&blk) ⇒ Object
351
352
353
354
|
# File 'lib/mayak/monads/result.rb', line 351
def tee(&blk)
blk.call(@success_value)
self
end
|
#to_maybe ⇒ Object
328
329
330
|
# File 'lib/mayak/monads/result.rb', line 328
def to_maybe
Mayak::Monads::Maybe::Some.new(@success_value)
end
|
#to_try(&blk) ⇒ Object
323
324
325
|
# File 'lib/mayak/monads/result.rb', line 323
def to_try(&blk)
Mayak::Monads::Try::Success.new(@success_value)
end
|