class Dry::Monads::Maybe::None

Represents an absence of a value, i.e. the value nil.

@api public

Attributes

instance[R]
trace[R]

Line where the value was constructed

@return [String]

Private Class Methods

method_missing(m, *) click to toggle source

@api private

Calls superclass method
# 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
new(trace = RightBiased::Left.trace_caller) click to toggle source
Calls superclass method
# File lib/dry/monads/maybe.rb, line 212
def initialize(trace = RightBiased::Left.trace_caller)
  super()
  @trace = trace
end

Private Instance Methods

==(other)
Alias for: eql?
deconstruct() click to toggle source

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
eql?(other) click to toggle source

@api private

# File lib/dry/monads/maybe.rb, line 260
def eql?(other)
  other.is_a?(None)
end
Also aliased as: ==
filter(_ = Undefined) click to toggle source

@see Maybe::Some#filter

@return [Maybe::None]

# File lib/dry/monads/maybe.rb, line 287
def filter(_ = Undefined)
  self
end
hash() click to toggle source

@private

# File lib/dry/monads/maybe.rb, line 266
def hash
  None.instance.object_id
end
inspect()
Alias for: to_s
or(*args) { |*args| ... } click to toggle source

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
or_fmap(...) click to toggle source

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
to_result(fail = Unit) { || ... } click to toggle source

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
to_s() click to toggle source

@return [String]

# File lib/dry/monads/maybe.rb, line 254
def to_s
  "None"
end
Also aliased as: inspect