Class: Monadic::Maybe
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Monad
#==, #bind, #fetch, #initialize, #join, #map, #to_s
Constructor Details
This class inherits a constructor from Monadic::Monad
Class Method Details
.unit(value) ⇒ Object
3
4
5
6
|
# File 'lib/monadic/maybe.rb', line 3
def self.unit(value)
return Nothing if value.nil? || (value.respond_to?(:empty?) && value.empty?)
return Just.new(value)
end
|
Instance Method Details
#empty? ⇒ Boolean
12
13
14
|
# File 'lib/monadic/maybe.rb', line 12
def empty?
@value.respond_to?(:empty?) && @value.empty?
end
|
#select(proc = nil, &block) ⇒ Object
22
23
24
25
26
|
# File 'lib/monadic/maybe.rb', line 22
def select(proc = nil, &block)
return Maybe(@value.select(&block)) if @value.is_a?(::Enumerable)
return Nothing unless (proc || block).call(@value)
return self
end
|
#to_ary ⇒ Object
Also known as:
to_a
16
17
18
19
|
# File 'lib/monadic/maybe.rb', line 16
def to_ary
return [@value].flatten if @value.respond_to? :flatten
return [@value]
end
|
#truly? ⇒ Boolean
28
29
30
|
# File 'lib/monadic/maybe.rb', line 28
def truly?
@value == true
end
|