Class: Unparser::Either::Left

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

Instance Method Summary collapse

Methods inherited from Unparser::Either

#left?, #right?, wrap_error

Instance Method Details

#bind(&block) ⇒ Either::Left<Object>

Evaluate applicative block

Returns:



64
65
66
# File 'lib/unparser/either.rb', line 64

def bind(&block)
  require_block(&block)
end

#either(left, _right) ⇒ Object

Evaluate left side of branch

Parameters:

  • left (#call)
  • _right (#call)


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

def either(left, _right)
  left.call(value)
end

#fmap(&block) ⇒ Either::Left<Object>

Evaluate functor block

Returns:



57
58
59
# File 'lib/unparser/either.rb', line 57

def fmap(&block)
  require_block(&block)
end

#from_leftObject

Unwrap value from left

Returns:

  • (Object)


71
72
73
# File 'lib/unparser/either.rb', line 71

def from_left
  value
end

#from_rightObject

Unwrap value from right

Returns:

  • (Object)


79
80
81
82
83
84
85
# File 'lib/unparser/either.rb', line 79

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

#lmapEither::Right<Object>

Map over left value

Returns:



90
91
92
# File 'lib/unparser/either.rb', line 90

def lmap
  Left.new(yield(value))
end