Class: MPrelude::Either::Left
- Inherits:
-
MPrelude::Either
- Object
- MPrelude::Either
- MPrelude::Either::Left
- Defined in:
- lib/mprelude.rb
Instance Method Summary collapse
-
#bind(&block) ⇒ Either::Left<Object>
Evaluate applicative block.
-
#either(left, _right) ⇒ Object
Evaluate left side of branch.
-
#fmap(&block) ⇒ Either::Left<Object>
Evaluate functor block.
-
#from_left ⇒ Object
Unwrap value from left.
-
#from_right ⇒ Object
Unwrap value from right.
-
#lmap ⇒ Either::Right<Object>
Map over left value.
Methods inherited from MPrelude::Either
Instance Method Details
#bind(&block) ⇒ Either::Left<Object>
Evaluate applicative block
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
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
108 109 110 |
# File 'lib/mprelude.rb', line 108 def fmap(&block) require_block(&block) end |
#from_left ⇒ Object
Unwrap value from left
122 123 124 |
# File 'lib/mprelude.rb', line 122 def from_left value end |
#from_right ⇒ Object
Unwrap value from right
rubocop:disable Style/GuardClause
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 |
#lmap ⇒ Either::Right<Object>
Map over left value
143 144 145 |
# File 'lib/mprelude.rb', line 143 def lmap Left.new(yield(value)) end |