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



227
228
229
# File 'lib/dry/monads/right_biased.rb', line 227

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:



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

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:



298
299
300
# File 'lib/dry/monads/right_biased.rb', line 298

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:



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

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


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

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

#discardRightBiased::Left

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

Returns:



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

def discard
  self
end

#flattenRightBiased::Left

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

Returns:



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

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:



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

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)


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

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)


279
280
281
# File 'lib/dry/monads/right_biased.rb', line 279

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:



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

def tee(*)
  self
end

#value!Object

Raises an error on accessing internal value

Raises:



232
233
234
# File 'lib/dry/monads/right_biased.rb', line 232

def value!
  raise UnwrapError.new(self)
end

#value_or(val = nil) ⇒ Object

Returns the passed value

Returns:

  • (Object)


286
287
288
289
290
291
292
# File 'lib/dry/monads/right_biased.rb', line 286

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