Class: Unparser::Either::Right

Inherits:
Unparser::Either show all
Defined in:
lib/unparser/either.rb

Overview

Left

Instance Method Summary collapse

Methods inherited from Unparser::Either

#left?, #right?, wrap_error

Instance Method Details

#bind {|value| ... } ⇒ Either<Object>

Evaluate applicative block

Yields:

  • (value)

Returns:



114
115
116
# File 'lib/unparser/either.rb', line 114

def bind
  yield(value)
end

#either(_left, right) ⇒ Object

Evaluate right side of branch

Parameters:

  • _left (#call)
  • right (#call)


148
149
150
# File 'lib/unparser/either.rb', line 148

def either(_left, right)
  right.call(value)
end

#fmapEither::Right<Object>

Evaluate functor block

Returns:



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

def fmap
  Right.new(yield(value))
end

#from_leftObject

Unwrap value from left

Returns:

  • (Object)


122
123
124
125
126
127
128
# File 'lib/unparser/either.rb', line 122

def from_left
  if block_given?
    yield(value)
  else
    fail "Expected left value, got #{inspect}"
  end
end

#from_rightObject

Unwrap value from right

Returns:

  • (Object)


133
134
135
# File 'lib/unparser/either.rb', line 133

def from_right
  value
end

#lmap(&block) ⇒ Either::Right<Object>

Map over left value

Returns:



140
141
142
# File 'lib/unparser/either.rb', line 140

def lmap(&block)
  require_block(&block)
end