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



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

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

Instance Method Details

#and(_) ⇒ RightBiased::Left

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

Returns:



350
351
352
# File 'lib/dry/monads/right_biased.rb', line 350

def and(_)
  self
end

#applyRightBiased::Left

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

Returns:



326
327
328
# File 'lib/dry/monads/right_biased.rb', line 326

def apply(*)
  self
end

#bindRightBiased::Left

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

Returns:



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

def bind(*)
  self
end

#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


365
366
367
368
369
370
371
372
373
# File 'lib/dry/monads/right_biased.rb', line 365

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

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


384
385
386
387
388
389
390
# File 'lib/dry/monads/right_biased.rb', line 384

def deconstruct_keys(_)
  if @value.is_a?(::Hash)
    @value
  else
    EMPTY_HASH
  end
end

#discardRightBiased::Left

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

Returns:



334
335
336
# File 'lib/dry/monads/right_biased.rb', line 334

def discard
  self
end

#flattenRightBiased::Left

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

Returns:



342
343
344
# File 'lib/dry/monads/right_biased.rb', line 342

def flatten
  self
end

#fmapRightBiased::Left

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

Returns:



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

def fmap(*)
  self
end

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


296
297
298
# File 'lib/dry/monads/right_biased.rb', line 296

def or(*)
  raise NotImplementedError
end

#or_fmapRightBiased::Left, RightBiased::Right

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

Examples:

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

Returns:

Raises:

  • (NotImplementedError)


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

def or_fmap(*)
  raise NotImplementedError
end

#teeRightBiased::Left

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

Returns:



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

def tee(*)
  self
end

#value!Object

Raises an error on accessing internal value

Raises:



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

def value!
  raise UnwrapError.new(self)
end

#value_or(val = nil) ⇒ Object

Returns the passed value

Returns:

  • (Object)


314
315
316
317
318
319
320
# File 'lib/dry/monads/right_biased.rb', line 314

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