Class: Maybe
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from MonadPlus
guard
Methods included from Monad
#>>, #bind_const, included
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value
3
4
5
|
# File 'lib/do_notation/monads/maybe.rb', line 3
def value
@value
end
|
Class Method Details
.mzero ⇒ Object
20
21
22
|
# File 'lib/do_notation/monads/maybe.rb', line 20
def self.mzero
unit(nil)
end
|
.unit(value) ⇒ Object
6
7
8
|
# File 'lib/do_notation/monads/maybe.rb', line 6
def self.unit value
self.new(value)
end
|
Instance Method Details
#bind(&f) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/do_notation/monads/maybe.rb', line 10
def bind &f
if value.nil?
self
else
f.call(value)
end
end
|
#mplus(m) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/do_notation/monads/maybe.rb', line 24
def mplus m
if value.nil?
m
else
self
end
end
|