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, 1)[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:



359
360
361
# File 'lib/dry/monads/right_biased.rb', line 359

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:



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

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


374
375
376
377
378
379
380
381
382
# File 'lib/dry/monads/right_biased.rb', line 374

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


393
394
395
396
397
398
399
# File 'lib/dry/monads/right_biased.rb', line 393

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:



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

def discard
  self
end

#flattenRightBiased::Left

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

Returns:



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

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_fmap('no value') # => Some("no value")
Dry::Monads.None.or_fmap { Time.now } # => Some(current time)

Returns:

Raises:

  • (NotImplementedError)


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

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, self
end

#value_or(val = nil) ⇒ Object

Returns the passed value

Returns:

  • (Object)


323
324
325
326
327
328
329
# File 'lib/dry/monads/right_biased.rb', line 323

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



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

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