lib/dry/monads/right_biased.rb
# Applies the stored value to the given argument if the argument has type of Right,
# otherwise returns the argument.
#
# @example happy path
#   create_user = Dry::Monads::Success(CreateUser.new)
#   name = Success("John")
#   create_user.apply(name) # equivalent to CreateUser.new.call("John")
#
# @example unhappy path
#   name = Failure(:name_missing)
#   create_user.apply(name) # => Failure(:name_missing)
#
# @return [RightBiased::Left,RightBiased::Right]
Applies the stored value to the given argument if the argument has type of Right,
otherwise returns the argument.
Applies the stored value to the given argument if the argument has type of Right otherwise returns the argument .
def apply(val = Undefined)
          unless @value.respond_to?(:call)
            raise TypeError, "Cannot apply #{ val.inspect } to #{ @value.inspect }"
          end
          Undefined.default(val) { yield }.fmap { |unwrapped| curry.(unwrapped) }
        end
def apply ( val = Undefined ) unless @value . respond_to? ( :call ) raise TypeError , "Cannot apply #{ val.inspect } to #{ @value.inspect }" end Undefined . default ( val ) { yield } . fmap { | unwrapped | curry . ( unwrapped ) } end
Applies the stored value to the given argument if the argument has type of Right,
otherwise returns the argument.
Applies the stored value to the given argument if the argument has type of Right otherwise returns the argument .
None
RightBiased::Left,RightBiased::Right
val
<not_specific>
example
happy path create_user = Dry::Monads::Success(CreateUser.new) name = Success("John") create_user.apply(name) # equivalent to CreateUser.new.call("John")
happy path create_user = Dry :: Monads :: Success ( CreateUser . new ) name = Success ( " John " ) create_user . apply ( name ) # equivalent to CreateUser . new . call ( " John " )
example
unhappy path name = Failure(:name_missing) create_user.apply(name) # => Failure(:name_missing)
unhappy path name = Failure ( : name_missing ) create_user . apply ( name ) # = > Failure ( : name_missing )