class Dry::Monads::Maybe::None
Represents an absence of a value, i.e. the value nil.
@api public
Attributes
Line where the value was constructed
@return [String]
Private Class Methods
@api private
# File lib/dry/monads/maybe.rb, line 198 def self.method_missing(m, *) # rubocop:disable Style/MissingRespondToMissing if (instance.methods(true) - methods(true)).include?(m) raise ConstructorNotAppliedError.new(m, :None) else super end end
# File lib/dry/monads/maybe.rb, line 212 def initialize(trace = RightBiased::Left.trace_caller) super() @trace = trace end
Private Instance Methods
Pattern matching
@example
case Some(:foo) in Some(Integer) then ... in Some(:bar) then ... in None() then ... end
@api private
# File lib/dry/monads/maybe.rb, line 280 def deconstruct EMPTY_ARRAY end
@api private
# File lib/dry/monads/maybe.rb, line 260 def eql?(other) other.is_a?(None) end
@see Maybe::Some#filter
@return [Maybe::None]
# File lib/dry/monads/maybe.rb, line 287 def filter(_ = Undefined) self end
@private
# File lib/dry/monads/maybe.rb, line 266 def hash None.instance.object_id end
If a block is given passes internal value to it and returns the result, otherwise simply returns the parameter val.
@example
Dry::Monads.None.or('no value') # => "no value" Dry::Monads.None.or { Time.now } # => current time
@param args [Array<Object>] if no block given the first argument will be returned
otherwise arguments will be transparently passed to the block
@return [Object]
# File lib/dry/monads/maybe.rb, line 231 def or(*args) if block_given? yield(*args) else args[0] end end
A lifted version of ‘#or`. Applies `Maybe.coerce` to the passed value or to the block result.
@example
Dry::Monads.None.or_fmap('no value') # => Some("no value") Dry::Monads.None.or_fmap { Time.now } # => Some(current time)
@param args [Array<Object>] arguments will be passed to the underlying ‘#or` call @return [Maybe::Some, Maybe::None
] Lifted `#or` result, i.e. nil will be mapped to None
,
other values will be wrapped with Some
# File lib/dry/monads/maybe.rb, line 249 def or_fmap(...) Maybe.coerce(self.or(...)) end
Converts to Failure(fallback_value)
@param fail [#call] Fallback value @param block [Proc] Fallback block @return [Failure<Any>]
# File lib/dry/monads/result.rb, line 419 def to_result(fail = Unit) if block_given? Result::Failure.new(yield) else Result::Failure.new(fail) end end
@return [String]
# File lib/dry/monads/maybe.rb, line 254 def to_s "None" end