Class: Dry::Monads::Maybe::Some
- Inherits:
-
Dry::Monads::Maybe
- Object
- Dry::Monads::Maybe
- Dry::Monads::Maybe::Some
- Includes:
- RightBiased::Right
- Defined in:
- lib/dry/monads/maybe.rb,
lib/dry/monads/result.rb
Overview
Represents a value that is present, i.e. not nil.
Class Method Summary collapse
-
.[](*value) ⇒ Object
Shortcut for Some([...]).
Instance Method Summary collapse
-
#fmap(*args, &block) ⇒ Maybe::Some, Maybe::None
(also: #maybe)
Does the same thing as #bind except it also wraps the value in an instance of Maybe::Some monad.
-
#initialize(value = Undefined) ⇒ Some
constructor
A new instance of Some.
-
#to_result(fail = Unit, &block) ⇒ Success<Any>
Converts to Sucess(value!).
- #to_s ⇒ String (also: #inspect)
Methods included from RightBiased::Right
#===, #and, #apply, #bind, #deconstruct, #deconstruct_keys, #discard, #flatten, included, #or, #or_fmap, #tee, #value!, #value_or
Methods inherited from Dry::Monads::Maybe
#as_json, coerce, json_create, #monad, #none?, pure, #some?, #to_json, #to_maybe, #to_monad, to_proc
Methods included from Transformer
Constructor Details
Class Method Details
.[](*value) ⇒ Object
Shortcut for Some([...])
@example include Dry::Monads[:maybe]
def call Some[200, {}, ['ok']] # => Some([200, {}, ['ok']]) end
101 102 103 |
# File 'lib/dry/monads/maybe.rb', line 101 def self.[](*value) new(value) end |
Instance Method Details
#fmap(*args, &block) ⇒ Maybe::Some, Maybe::None Also known as: maybe
Does the same thing as #bind except it also wraps the value in an instance of Maybe::Some monad. This allows for easier chaining of calls.
120 121 122 |
# File 'lib/dry/monads/maybe.rb', line 120 def fmap(*args, &block) Maybe.coerce(bind(*args, &block)) end |
#to_result(fail = Unit, &block) ⇒ Success<Any>
Converts to Sucess(value!)
389 390 391 |
# File 'lib/dry/monads/result.rb', line 389 def to_result(fail = Unit, &block) Result::Success.new(@value) end |
#to_s ⇒ String Also known as: inspect
126 127 128 129 130 131 132 |
# File 'lib/dry/monads/maybe.rb', line 126 def to_s if Unit.equal?(@value) 'Some()' else "Some(#{@value.inspect})" end end |