class Right

Public Class Methods

new(value) click to toggle source
# File lib/totally_lazy/either.rb, line 104
def initialize(value)
  @value = value
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/totally_lazy/either.rb, line 143
def <=>(other)
  @value <=> other.right_value
end
flat_map(fn=nil, &block) click to toggle source
# File lib/totally_lazy/either.rb, line 134
def flat_map(fn=nil, &block) # a function which returns an either
  assert_funcs(fn, block_given?)
  block_given? ? block.call(@value) : fn.(@value)
end
fold(seed, fn_left, fn_right) click to toggle source
# File lib/totally_lazy/either.rb, line 139
def fold(seed, fn_left, fn_right)
  fn_right.(seed, @value)
end
is_left?() click to toggle source
# File lib/totally_lazy/either.rb, line 108
def is_left?
  false
end
is_right?() click to toggle source
# File lib/totally_lazy/either.rb, line 112
def is_right?
  true
end
left_value() click to toggle source
# File lib/totally_lazy/either.rb, line 116
def left_value
  raise NoSuchElementException.new
end
map(fn=nil, &block) click to toggle source
# File lib/totally_lazy/either.rb, line 124
def map(fn=nil, &block)
  assert_funcs(fn, block_given?)
  right(block_given? ? block.call(@value) : fn.(@value))
end
map_left(fn=nil, &block) click to toggle source
# File lib/totally_lazy/either.rb, line 129
def map_left(fn=nil, &block)
  assert_funcs(fn, block_given?)
  self
end
right_value() click to toggle source
# File lib/totally_lazy/either.rb, line 120
def right_value
  @value
end
to_s() click to toggle source
# File lib/totally_lazy/either.rb, line 147
def to_s
  "right(#{@value})"
end