Class: Monadic::Maybe
Class Method Summary collapse
Instance Method Summary collapse
-
#empty? ⇒ Boolean
True if the underlying object responds to #empty?, false otherwise.
-
#select(proc = nil, &block) ⇒ Failure, Success
The Maybe Monad filtered with the block or proc expression.
-
#truly? ⇒ true, false
True if the underlying value is true.
Methods included from Monad
#==, #bind, #fetch, #flat_map, #initialize, #join, #map, #to_ary, #to_s
Class Method Details
Instance Method Details
#empty? ⇒ Boolean
Returns true if the underlying object responds to #empty?, false otherwise.
15 16 17 |
# File 'lib/monadic/maybe.rb', line 15 def empty? @value.respond_to?(:empty?) && @value.empty? end |
#select(proc = nil, &block) ⇒ Failure, Success
Returns the Maybe Monad filtered with the block or proc expression.
20 21 22 23 24 25 |
# File 'lib/monadic/maybe.rb', line 20 def select(proc = nil, &block) func = (proc || block) return Maybe(@value.select {|v| func.call(v) }) if @value.respond_to? :select return Nothing unless func.call(@value) return self end |
#truly? ⇒ true, false
Returns true if the underlying value is true.
28 29 30 |
# File 'lib/monadic/maybe.rb', line 28 def truly? @value == true end |