Module: Dry::Monads::RightBiased::Left

Included in:
Maybe::None, Dry::Monads::Result::Failure, Try::Error
Defined in:
lib/dry/monads/right_biased.rb

Overview

Left/wrong/erroneous part

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.trace_callerString

Returns Caller location.

Returns:

  • (String)

    Caller location



240
# File 'lib/dry/monads/right_biased.rb', line 240

def self.trace_caller = caller_locations(2, 1)[0].to_s

Instance Method Details

#and(_) ⇒ RightBiased::Left

Returns self back. It exists to keep the interface identical to that of Right.

Returns:



322
# File 'lib/dry/monads/right_biased.rb', line 322

def and(_, &) = self

#applyRightBiased::Left

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

Returns:



304
# File 'lib/dry/monads/right_biased.rb', line 304

def apply(...) = self

#bindRightBiased::Left

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

Returns:



249
# File 'lib/dry/monads/right_biased.rb', line 249

def bind(...) = self

#deconstructObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Pattern matching

Examples:

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


339
340
341
342
343
344
345
346
347
# File 'lib/dry/monads/right_biased.rb', line 339

def deconstruct
  if Unit.equal?(@value)
    []
  elsif @value.is_a?(::Array)
    @value
  else
    [@value]
  end
end

#deconstruct_keys(keys) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Pattern matching hash values

Examples:

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


358
359
360
361
362
363
364
# File 'lib/dry/monads/right_biased.rb', line 358

def deconstruct_keys(keys)
  if @value.respond_to?(:deconstruct_keys)
    @value.deconstruct_keys(keys)
  else
    EMPTY_HASH
  end
end

#discardRightBiased::Left

Returns self back. It exists to keep the interface identical to that of Right.

Returns:



310
# File 'lib/dry/monads/right_biased.rb', line 310

def discard = self

#flattenRightBiased::Left

Returns self back. It exists to keep the interface identical to that of Right.

Returns:



316
# File 'lib/dry/monads/right_biased.rb', line 316

def flatten = self

#fmapRightBiased::Left

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

Returns:



261
# File 'lib/dry/monads/right_biased.rb', line 261

def fmap(...) = self

#orObject

Left-biased #bind version.

Examples:

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

Returns:

  • (Object)

Raises:

  • (NotImplementedError)


271
# File 'lib/dry/monads/right_biased.rb', line 271

def or(...) = raise NotImplementedError

#or_fmapRightBiased::Left, RightBiased::Right

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

Examples:

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

Returns:

Raises:

  • (NotImplementedError)


287
# File 'lib/dry/monads/right_biased.rb', line 287

def or_fmap(...) = raise NotImplementedError

#teeRightBiased::Left

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

Returns:



255
# File 'lib/dry/monads/right_biased.rb', line 255

def tee(...) = self

#value!Object

Raises an error on accessing internal value

Raises:



243
# File 'lib/dry/monads/right_biased.rb', line 243

def value! = raise UnwrapError, self

#value_or(val = nil) ⇒ Object

Returns the passed value

Returns:

  • (Object)


292
293
294
295
296
297
298
# File 'lib/dry/monads/right_biased.rb', line 292

def value_or(val = nil)
  if block_given?
    yield
  else
    val
  end
end

#|(alt) ⇒ RightBiased::Right, RightBiased::Left

Returns the passed value. Works in pair with Right#|.



278
# File 'lib/dry/monads/right_biased.rb', line 278

def |(alt) = self.or(alt)