Module: Dry::Monads::Try::Mixin
- Includes:
- Constructors
- Defined in:
- lib/dry/monads/try.rb
Overview
A module that can be included for easier access to Try monads.
Defined Under Namespace
Modules: Constructors
Constant Summary collapse
- Try =
Try
Instance Method Summary collapse
-
#Error(error = Undefined, &block) ⇒ Object
Error constructor.
-
#Value(value = Undefined, exceptions = DEFAULT_EXCEPTIONS, &block) ⇒ Object
Value constructor.
Methods included from Constructors
Instance Method Details
#Error(value) ⇒ Try::Error #Error(&block) ⇒ Try::Error
Error constructor
268 269 270 271 272 |
# File 'lib/dry/monads/try.rb', line 268 def Error(error = Undefined, &block) v = Undefined.default(error, block) raise ArgumentError, 'No value given' if v.nil? Try::Error.new(v) end |
#Value(value) ⇒ Try::Value #Value(&block) ⇒ Try::Value
Value constructor
252 253 254 255 256 |
# File 'lib/dry/monads/try.rb', line 252 def Value(value = Undefined, exceptions = DEFAULT_EXCEPTIONS, &block) v = Undefined.default(value, block) raise ArgumentError, 'No value given' if !value.nil? && v.nil? Value.new(exceptions, v) end |