Class: MPrelude::Either::Left
- Inherits:
-
MPrelude::Either
- Object
- MPrelude::Either
- MPrelude::Either::Left
- Defined in:
- lib/mprelude.rb
Instance Method Summary collapse
-
#apply(&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
#apply(&block) ⇒ Either::Left<Object>
Evaluate applicative block
117 118 119 |
# File 'lib/mprelude.rb', line 117 def apply(&block) require_block(&block) end |
#either(left, _right) ⇒ Object
Evaluate left side of branch
153 154 155 |
# File 'lib/mprelude.rb', line 153 def either(left, _right) left.call(value) end |
#fmap(&block) ⇒ Either::Left<Object>
Evaluate functor block
110 111 112 |
# File 'lib/mprelude.rb', line 110 def fmap(&block) require_block(&block) end |
#from_left ⇒ Object
Unwrap value from left
124 125 126 |
# File 'lib/mprelude.rb', line 124 def from_left value end |
#from_right ⇒ Object
Unwrap value from right
rubocop:disable Style/GuardClause
133 134 135 136 137 138 139 |
# File 'lib/mprelude.rb', line 133 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
145 146 147 |
# File 'lib/mprelude.rb', line 145 def lmap Left.new(yield(value)) end |