Class: Kind::Either::Right
- Inherits:
-
Either::Monad
- Object
- Either::Monad
- Kind::Either::Right
- Defined in:
- lib/kind/either/right.rb
Instance Method Summary collapse
- #inspect ⇒ Object
- #map(&fn) ⇒ Object (also: #then, #and_then)
- #map!(&fn) ⇒ Object (also: #then!, #and_then!)
- #right? ⇒ Boolean
- #value_or(_default = UNDEFINED, &block) ⇒ Object
Instance Method Details
#inspect ⇒ Object
34 35 36 |
# File 'lib/kind/either/right.rb', line 34 def inspect '#<%s value=%p>' % ['Kind::Right', value] end |
#map(&fn) ⇒ Object Also known as: then, and_then
13 14 15 16 17 18 19 |
# File 'lib/kind/either/right.rb', line 13 def map(&fn) map!(&fn) rescue Kind::Monad::Error => e raise e rescue StandardError => e Either::Left[e] end |
#map!(&fn) ⇒ Object Also known as: then!, and_then!
21 22 23 24 25 26 27 |
# File 'lib/kind/either/right.rb', line 21 def map!(&fn) monad = fn.call(@value) return monad if Either::Monad === monad raise Kind::Monad::Error.new('Kind::Right | Kind::Left', monad) end |
#value_or(_default = UNDEFINED, &block) ⇒ Object
9 10 11 |
# File 'lib/kind/either/right.rb', line 9 def value_or(_default = UNDEFINED, &block) @value end |