Class: Kind::Either::Right
- Inherits:
-
Monad
- Object
- Monad
- Kind::Either::Right
show all
- Defined in:
- lib/kind/either/right.rb
Instance Attribute Summary
Attributes inherited from Monad
#value
Instance Method Summary
collapse
Methods inherited from Monad
#===, #either?, #initialize, #left?, #on, #on_left, #on_right
Instance Method Details
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
|
5
6
7
|
# File 'lib/kind/either/right.rb', line 5
def right?
true
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
|