Class: Rumonade::Left

Inherits:
Either
  • Object
show all
Defined in:
lib/rumonade/either.rb

Overview

The left side of the disjoint union, as opposed to the Right side.

Constant Summary

Constants inherited from Either

Either::DEFAULT_CONCAT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Either

#+, #fold, #left, #left?, #lift, #lift_to_a, #right, #right?, #swap

Constructor Details

#initialize(left_value) ⇒ Left

Returns a new instance of Left.

Parameters:

  • left_value

    the value to store in a Left, usually representing a failure result



98
99
100
# File 'lib/rumonade/either.rb', line 98

def initialize(left_value)
  @left_value = left_value
end

Instance Attribute Details

#left_valueObject (readonly)

Returns the left value

Returns:

  • Returns the left value



103
104
105
# File 'lib/rumonade/either.rb', line 103

def left_value
  @left_value
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if other is a Left with an equal left value

Returns:

  • (Boolean)

    Returns true if other is a Left with an equal left value



106
107
108
# File 'lib/rumonade/either.rb', line 106

def ==(other)
  other.is_a?(Left) && other.left_value == self.left_value
end

#inspectString

Returns a String containing a human-readable representation of this object.

Returns:

  • (String)

    Returns a String containing a human-readable representation of this object.



116
117
118
# File 'lib/rumonade/either.rb', line 116

def inspect
  "Left(#{left_value.inspect})"
end

#to_sString

Returns a String representation of this object.

Returns:

  • (String)

    Returns a String representation of this object.



111
112
113
# File 'lib/rumonade/either.rb', line 111

def to_s
  "Left(#{left_value})"
end