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



94
95
96
# File 'lib/rumonade/either.rb', line 94

def initialize(left_value)
  @left_value = left_value
end

Instance Attribute Details

#left_valueObject (readonly)

Returns the left value

Returns:

  • Returns the left value



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

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



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

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.



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

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.



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

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