Class: MPrelude::Either::Right
- Inherits:
-
MPrelude::Either
- Object
- MPrelude::Either
- MPrelude::Either::Right
- Defined in:
- lib/mprelude.rb
Overview
Left
Instance Method Summary collapse
-
#bind {|value| ... } ⇒ Either<Object>
Evaluate applicative block.
-
#either(_left, right) ⇒ Object
Evaluate right side of branch.
-
#fmap ⇒ Either::Right<Object>
Evaluate functor block.
-
#from_left ⇒ Object
Unwrap value from left.
-
#from_right ⇒ Object
Unwrap value from right.
-
#lmap(&block) ⇒ Either::Right<Object>
Map over left value.
Methods inherited from MPrelude::Either
Instance Method Details
#bind {|value| ... } ⇒ Either<Object>
Evaluate applicative block
167 168 169 |
# File 'lib/mprelude.rb', line 167 def bind yield(value) end |
#either(_left, right) ⇒ Object
Evaluate right side of branch
203 204 205 |
# File 'lib/mprelude.rb', line 203 def either(_left, right) right.call(value) end |
#fmap ⇒ Either::Right<Object>
Evaluate functor block
160 161 162 |
# File 'lib/mprelude.rb', line 160 def fmap Right.new(yield(value)) end |
#from_left ⇒ Object
Unwrap value from left
rubocop:disable Style/GuardClause
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_right ⇒ Object
Unwrap value from right
188 189 190 |
# File 'lib/mprelude.rb', line 188 def from_right value end |
#lmap(&block) ⇒ Either::Right<Object>
Map over left value
195 196 197 |
# File 'lib/mprelude.rb', line 195 def lmap(&block) require_block(&block) end |