module Dry::Monads::RightBiased::Left

Left/wrong/erroneous part

@api public

Public Class Methods

trace_caller() click to toggle source

@private @return [String] Caller location

# File lib/dry/monads/right_biased.rb, line 255
def self.trace_caller
  caller_locations(2, 1)[0].to_s
end

Public Instance Methods

and(_) click to toggle source

Returns self back. It exists to keep the interface identical to that of {RightBiased::Right}.

@return [RightBiased::Left]

# File lib/dry/monads/right_biased.rb, line 359
def and(_)
  self
end
apply(*) click to toggle source

Ignores the input parameter and returns self. It exists to keep the interface identical to that of {RightBiased::Right}.

@return [RightBiased::Left]

# File lib/dry/monads/right_biased.rb, line 335
def apply(*)
  self
end
bind(*) click to toggle source

Ignores the input parameter and returns self. It exists to keep the interface identical to that of {RightBiased::Right}.

@return [RightBiased::Left]

# File lib/dry/monads/right_biased.rb, line 268
def bind(*)
  self
end
deconstruct() click to toggle source

Pattern matching

@example

case Success(x)
in Success(Integer) then ...
in Success(2..100) then ...
in Success(2..200 => code) then ...
in Failure(_) then ...
end

@api private

# File lib/dry/monads/right_biased.rb, line 374
def deconstruct
  if Unit.equal?(@value)
    []
  elsif @value.is_a?(::Array)
    @value
  else
    [@value]
  end
end
deconstruct_keys(keys) click to toggle source

Pattern matching hash values

@example

case Failure(x)
in Failure(code: 400...500) then :user_error
in Failure(code: 500...600) then :server_error
end

@api private

# File lib/dry/monads/right_biased.rb, line 393
def deconstruct_keys(keys)
  if @value.respond_to?(:deconstruct_keys)
    @value.deconstruct_keys(keys)
  else
    EMPTY_HASH
  end
end
discard() click to toggle source

Returns self back. It exists to keep the interface identical to that of {RightBiased::Right}.

@return [RightBiased::Left]

# File lib/dry/monads/right_biased.rb, line 343
def discard
  self
end
flatten() click to toggle source

Returns self back. It exists to keep the interface identical to that of {RightBiased::Right}.

@return [RightBiased::Left]

# File lib/dry/monads/right_biased.rb, line 351
def flatten
  self
end
fmap(*) click to toggle source

Ignores the input parameter and returns self. It exists to keep the interface identical to that of {RightBiased::Right}.

@return [RightBiased::Left]

# File lib/dry/monads/right_biased.rb, line 284
def fmap(*)
  self
end
or(*) click to toggle source

Left-biased bind version.

@example

Dry::Monads.Left(ArgumentError.new('error message')).or(&:message) # => "error message"
Dry::Monads.None.or('no value') # => "no value"
Dry::Monads.None.or { Time.now } # => current time

@return [Object]

# File lib/dry/monads/right_biased.rb, line 296
def or(*)
  raise NotImplementedError
end
or_fmap(*) click to toggle source

A lifted version of ‘#or`. This is basically `#or` + `#fmap`.

@example

Dry::Monads.None.or_fmap('no value') # => Some("no value")
Dry::Monads.None.or_fmap { Time.now } # => Some(current time)

@return [RightBiased::Left, RightBiased::Right]

# File lib/dry/monads/right_biased.rb, line 316
def or_fmap(*)
  raise NotImplementedError
end
tee(*) click to toggle source

Ignores the input parameter and returns self. It exists to keep the interface identical to that of {RightBiased::Right}.

@return [RightBiased::Left]

# File lib/dry/monads/right_biased.rb, line 276
def tee(*)
  self
end
value!() click to toggle source

Raises an error on accessing internal value

# File lib/dry/monads/right_biased.rb, line 260
def value!
  raise UnwrapError, self
end
value_or(val = nil) { || ... } click to toggle source

Returns the passed value

@return [Object]

# File lib/dry/monads/right_biased.rb, line 323
def value_or(val = nil)
  if block_given?
    yield
  else
    val
  end
end
|(alt) click to toggle source

Returns the passed value. Works in pair with {RightBiased::Right#|}.

@param alt [RightBiased::Right, RightBiased::Left]

@return [RightBiased::Right, RightBiased::Left]

# File lib/dry/monads/right_biased.rb, line 305
def |(alt)
  self.or(alt)
end