Class: MPrelude::Either::Right

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

Overview

Left

Instance Method Summary collapse

Methods inherited from MPrelude::Either

#left?, #right?, wrap_error

Instance Method Details

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

Evaluate applicative block

Yields:

  • (value)

Returns:



167
168
169
# File 'lib/mprelude.rb', line 167

def bind
  yield(value)
end

#either(_left, right) ⇒ Object

Evaluate right side of branch

Parameters:

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


203
204
205
# File 'lib/mprelude.rb', line 203

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

#fmapEither::Right<Object>

Evaluate functor block

Returns:



160
161
162
# File 'lib/mprelude.rb', line 160

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

#from_leftObject

Unwrap value from left

rubocop:disable Style/GuardClause

Returns:

  • (Object)


176
177
178
179
180
181
182
# File 'lib/mprelude.rb', line 176

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)


188
189
190
# File 'lib/mprelude.rb', line 188

def from_right
  value
end

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

Map over left value

Returns:



195
196
197
# File 'lib/mprelude.rb', line 195

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