Class: MPrelude::Either::Left

Inherits:
MPrelude::Either show all
Defined in:
lib/mprelude.rb

Instance Method Summary collapse

Methods inherited from MPrelude::Either

#left?, #right?, wrap_error

Instance Method Details

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

Evaluate applicative block

Returns:



115
116
117
# File 'lib/mprelude.rb', line 115

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

#either(left, _right) ⇒ Object

Evaluate left side of branch

Parameters:

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


151
152
153
# File 'lib/mprelude.rb', line 151

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

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

Evaluate functor block

Returns:



108
109
110
# File 'lib/mprelude.rb', line 108

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

#from_leftObject

Unwrap value from left

Returns:

  • (Object)


122
123
124
# File 'lib/mprelude.rb', line 122

def from_left
  value
end

#from_rightObject

Unwrap value from right

rubocop:disable Style/GuardClause

Returns:

  • (Object)


131
132
133
134
135
136
137
# File 'lib/mprelude.rb', line 131

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:



143
144
145
# File 'lib/mprelude.rb', line 143

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