class Blank
The class represents a lack of something.
Public Instance Methods
Is this wrapped value equal to the given wrapped value? All blank values are equal to each other.
> nil.wrapped == nil.wrapped > 1.wrapped == nil.wrapped
# File lib/wrapped/blank.rb, line 96 def ==(other) other.is_a?(Blank) end
Call the block then return itself. This is chainable. See present for its companion.
w.blank { puts “I got nothing” }.present {|n| puts “got #{n}” }
# File lib/wrapped/blank.rb, line 33 def blank(&block) block.call self end
True; this is an instance of nothing.
# File lib/wrapped/blank.rb, line 70 def blank? true end
Produce the empty list.
This class mixes in the Enumerable module, which relies on this.
> w.each {|n| puts n }
# File lib/wrapped/blank.rb, line 43 def each self end
Do nothing, returning itself.
> w.flat_map {|n| n+1 }
# File lib/wrapped/blank.rb, line 77 def flat_map self end
Do nothing, returning itself.
> w.fmap {|n| n+1 }
# File lib/wrapped/blank.rb, line 84 def fmap self end
Produces itself.
# File lib/wrapped/blank.rb, line 60 def grep(*) self end
Does nothing, returning itself. This is chainable. See blank for its companion.
w.present.blank { puts “Missing” }
# File lib/wrapped/blank.rb, line 25 def present self end
False; this is not an instance of a wrapped value.
# File lib/wrapped/blank.rb, line 65 def present? false end
Produces itself.
# File lib/wrapped/blank.rb, line 55 def reject self end
Produces itself.
# File lib/wrapped/blank.rb, line 48 def select self end
It is an error (specifically, an IndexError) to use this method.
# File lib/wrapped/blank.rb, line 6 def unwrap raise IndexError.new("Blank has no value") end
Produce the value that is passed in.
> w.unwrap_or(0)
# File lib/wrapped/blank.rb, line 13 def unwrap_or(default = nil) if block_given? yield else default end end