Class: Dry::Monads::Maybe::None
- Inherits:
-
Maybe
- Object
- Maybe
- Dry::Monads::Maybe::None
- Includes:
- RightBiased::Left
- Defined in:
- lib/dry/monads/maybe.rb,
lib/dry/monads/result.rb
Overview
Represents an absence of a value, i.e. the value nil.
Instance Attribute Summary collapse
- #instance ⇒ Object readonly
-
#trace ⇒ String
readonly
Line where the value was constructed.
Instance Method Summary collapse
-
#deconstruct ⇒ Object
private
Pattern matching.
- #eql?(other) ⇒ Boolean (also: #==) private
- #filter(_ = Undefined) ⇒ Maybe::None
- #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 ⇒ Maybe::Some, Maybe::None
A lifted version of
#or. -
#to_result(fail = Unit) ⇒ Failure<Any>
Converts to Failure(fallback_value).
- #to_s ⇒ String (also: #inspect)
Methods included from RightBiased::Left
#and, #apply, #bind, #deconstruct_keys, #discard, #flatten, #fmap, #tee, trace_caller, #value!, #value_or, #|
Constructor Details
#initialize(trace = RightBiased::Left.trace_caller) ⇒ None
Returns a new instance of None.
198 199 200 201 |
# File 'lib/dry/monads/maybe.rb', line 198 def initialize(trace = RightBiased::Left.trace_caller) super() @trace = trace end |
Instance Attribute Details
#instance ⇒ Object (readonly)
181 182 183 |
# File 'lib/dry/monads/maybe.rb', line 181 def instance @instance end |
#trace ⇒ String (readonly)
Line where the value was constructed
196 197 198 |
# File 'lib/dry/monads/maybe.rb', line 196 def trace @trace end |
Instance Method Details
#deconstruct ⇒ Object
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.
Pattern matching
262 |
# File 'lib/dry/monads/maybe.rb', line 262 def deconstruct = EMPTY_ARRAY |
#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.
242 |
# File 'lib/dry/monads/maybe.rb', line 242 def eql?(other) = other.is_a?(None) |
#filter(_ = Undefined) ⇒ Maybe::None
267 |
# File 'lib/dry/monads/maybe.rb', line 267 def filter(_ = Undefined, &) = self |
#hash ⇒ Object
247 |
# File 'lib/dry/monads/maybe.rb', line 247 def hash = None.instance.object_id |
#or(*args) ⇒ Object
If a block is given passes internal value to it and returns the result, otherwise simply returns the parameter val.
217 218 219 220 221 222 223 |
# File 'lib/dry/monads/maybe.rb', line 217 def or(*args) if block_given? yield(*args) else args[0] end end |
#or_fmap ⇒ Maybe::Some, Maybe::None
A lifted version of #or. Applies Maybe.coerce to the passed value or
to the block result.
235 |
# File 'lib/dry/monads/maybe.rb', line 235 def or_fmap(...) = Maybe.coerce(self.or(...)) |
#to_result(fail = Unit) ⇒ Failure<Any>
Converts to Failure(fallback_value)
383 384 385 386 387 388 389 |
# File 'lib/dry/monads/result.rb', line 383 def to_result(fail = Unit) if block_given? Result::Failure.new(yield) else Result::Failure.new(fail) end end |
#to_s ⇒ String Also known as: inspect
238 |
# File 'lib/dry/monads/maybe.rb', line 238 def to_s = "None" |