Class: Dry::Monads::Maybe::None
- Inherits:
-
Dry::Monads::Maybe
- Object
- Dry::Monads::Maybe
- Dry::Monads::Maybe::None
- Includes:
- RightBiased::Left
- Defined in:
- lib/dry/monads/maybe.rb
Overview
Represents an absence of a value, i.e. the value nil.
Instance Attribute Summary collapse
-
#trace ⇒ String
readonly
Line where the value was constructed.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==) private
- #hash ⇒ Object
-
#initialize(trace = RightBiased::Left.trace_caller) ⇒ None
constructor
A new instance of None.
-
#or(*args) ⇒ Object
If a block is given passes internal value to it and returns the result, otherwise simply returns the parameter val.
-
#or_fmap(*args, &block) ⇒ Maybe::Some, Maybe::None
A lifted version of
#or
. - #to_s ⇒ String (also: #inspect)
Methods included from RightBiased::Left
#apply, #bind, #discard, #fmap, #tee, trace_caller, #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
#initialize(trace = RightBiased::Left.trace_caller) ⇒ None
Returns a new instance of None.
131 132 133 |
# File 'lib/dry/monads/maybe.rb', line 131 def initialize(trace = RightBiased::Left.trace_caller) @trace = trace end |
Instance Attribute Details
#trace ⇒ String (readonly)
Line where the value was constructed
129 130 131 |
# File 'lib/dry/monads/maybe.rb', line 129 def trace @trace end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
174 175 176 |
# File 'lib/dry/monads/maybe.rb', line 174 def eql?(other) other.is_a?(None) end |
#hash ⇒ Object
180 181 182 |
# File 'lib/dry/monads/maybe.rb', line 180 def hash None.instance.object_id end |
#or(*args) ⇒ Object
If a block is given passes internal value to it and returns the result, otherwise simply returns the parameter val.
145 146 147 148 149 150 151 |
# File 'lib/dry/monads/maybe.rb', line 145 def or(*args) if block_given? yield(*args) else args[0] end end |
#or_fmap(*args, &block) ⇒ Maybe::Some, Maybe::None
A lifted version of #or
. Applies Maybe.coerce
to the passed value or
to the block result.
163 164 165 |
# File 'lib/dry/monads/maybe.rb', line 163 def or_fmap(*args, &block) Maybe.coerce(self.or(*args, &block)) end |
#to_s ⇒ String Also known as: inspect
168 169 170 |
# File 'lib/dry/monads/maybe.rb', line 168 def to_s 'None' end |