module Dry::Monads::RightBiased::Left
Left/wrong/erroneous part
@api public
Public Class Methods
@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
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
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
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
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
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
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
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
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
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
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
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
Raises an error on accessing internal value
# File lib/dry/monads/right_biased.rb, line 260 def value! raise UnwrapError, self end
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
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