Class: Fr::Maybe::Some
Constant Summary
Constants inherited
from Fr::Maybe
None
Instance Method Summary
collapse
Methods inherited from Fr::Maybe
bind, plus, run, unit, zero
Methods included from Fr::Monoid
#filter, #guard, #sum
Methods included from Fr::Monad
#applyM, #composeM, #filterM, #foldM, #forM, #join, #liftM, #mapM, #sequence, #unlessM, #whenM, #zipM
Methods included from Functor
#void
Constructor Details
#initialize(value) ⇒ Some
Returns a new instance of Some.
5
6
7
|
# File 'lib/fr/maybe.rb', line 5
def initialize(value)
@value = value
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
25
26
27
|
# File 'lib/fr/maybe.rb', line 25
def ==(other)
Maybe === other and other.fold(false){|x| x == @value }
end
|
#fold(default) {|@value| ... } ⇒ Object
13
14
15
|
# File 'lib/fr/maybe.rb', line 13
def fold(default)
yield @value
end
|
31
32
33
|
# File 'lib/fr/maybe.rb', line 31
def hash
@value.hash
end
|
35
36
37
|
# File 'lib/fr/maybe.rb', line 35
def inspect
"Fr.some(#{@value.inspect})"
end
|
9
10
11
|
# File 'lib/fr/maybe.rb', line 9
def map
Some.new(yield @value)
end
|
#none? ⇒ Boolean
21
22
23
|
# File 'lib/fr/maybe.rb', line 21
def none?
false
end
|
#some? ⇒ Boolean
17
18
19
|
# File 'lib/fr/maybe.rb', line 17
def some?
true
end
|