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.



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

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.



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

def and(_, &) = self

#applyRightBiased::Left

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



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

def apply(...) = self

#bindRightBiased::Left

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



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

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) then ...
in Success(2..100) then ...
in Success(2..200 => code) then ...
in Failure(_) then ...
end


332
333
334
335
336
337
338
339
340
# File 'lib/dry/monads/right_biased.rb', line 332

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


351
352
353
354
355
356
357
# File 'lib/dry/monads/right_biased.rb', line 351

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.



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

def discard = self

#flattenRightBiased::Left

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



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

def flatten = self

#fmapRightBiased::Left

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



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

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

Raises:

  • (NotImplementedError)


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

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)

Raises:

  • (NotImplementedError)


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

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.



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

def tee(...) = self

#value!Object

Raises an error on accessing internal value

Raises:



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

def value! = raise UnwrapError, self

#value_or(val = nil) ⇒ Object

Returns the passed value



289
290
291
292
293
294
295
# File 'lib/dry/monads/right_biased.rb', line 289

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#|.



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

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