Class: Left
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#flat_map(fn = nil, &block) ⇒ Object
a function which returns an either.
- #fold(seed, fn_left, fn_right) ⇒ Object
-
#initialize(value) ⇒ Left
constructor
A new instance of Left.
- #is_left? ⇒ Boolean
- #is_right? ⇒ Boolean
- #left_value ⇒ Object
- #map_left(fn = nil, &block) ⇒ Object
- #right_value ⇒ Object
- #to_s ⇒ Object
Methods inherited from Either
Constructor Details
#initialize(value) ⇒ Left
Returns a new instance of Left.
60 61 62 |
# File 'lib/totally_lazy/either.rb', line 60 def initialize(value) @value = value end |
Instance Method Details
#<=>(other) ⇒ Object
94 95 96 |
# File 'lib/totally_lazy/either.rb', line 94 def <=>(other) @value <=> other.left_value end |
#flat_map(fn = nil, &block) ⇒ Object
a function which returns an either
85 86 87 88 |
# File 'lib/totally_lazy/either.rb', line 85 def flat_map(fn=nil, &block) # a function which returns an either assert_funcs(fn, block_given?) self end |
#fold(seed, fn_left, fn_right) ⇒ Object
90 91 92 |
# File 'lib/totally_lazy/either.rb', line 90 def fold(seed, fn_left, fn_right) fn_left.(seed, @value) end |
#is_left? ⇒ Boolean
64 65 66 |
# File 'lib/totally_lazy/either.rb', line 64 def is_left? true end |
#is_right? ⇒ Boolean
68 69 70 |
# File 'lib/totally_lazy/either.rb', line 68 def is_right? false end |
#left_value ⇒ Object
72 73 74 |
# File 'lib/totally_lazy/either.rb', line 72 def left_value @value end |
#map_left(fn = nil, &block) ⇒ Object
80 81 82 83 |
# File 'lib/totally_lazy/either.rb', line 80 def map_left(fn=nil, &block) assert_funcs(fn, block_given?) left(block_given? ? block.call(@value) : fn.(@value)) end |
#right_value ⇒ Object
76 77 78 |
# File 'lib/totally_lazy/either.rb', line 76 def right_value raise NoSuchElementException.new end |
#to_s ⇒ Object
98 99 100 |
# File 'lib/totally_lazy/either.rb', line 98 def to_s "left(#{@value})" end |