class Mon::Monad::None

Public Class Methods

[]() click to toggle source

Return a new None object. Takes no args. None[] # ==> None

# File lib/monads/maybe.rb, line 176
def self.[]
  None.new
end
none() click to toggle source
# File lib/monads/maybe.rb, line 200
def self::none
  self.new
end

Protected Class Methods

new() click to toggle source
Calls superclass method
# File lib/monads/maybe.rb, line 184
def initialize
  super()
end

Public Instance Methods

==(o) click to toggle source
# File lib/monads/maybe.rb, line 192
def ==(o)
  eql?(o)
end
bind(&fun) click to toggle source

If we're wrapping a value, apply fun() to it. Otherwise, None stays None.

# File lib/monads/maybe.rb, line 145
def bind &fun
  self
end
eql?(other) click to toggle source
# File lib/monads/maybe.rb, line 188
def eql?(other)
  other.is_a? None
end
equal?(o) click to toggle source
# File lib/monads/maybe.rb, line 196
def equal?(o)
  eql?(o)
end
or(obj = nil, &f) click to toggle source

If there's a wrapped value, return it. Otherwise, either return the supplied object, or execute the supplied block. Eg: Maybe[1].or(5) # ==> 1 Maybe[nil].or(5) # ==> 5 Maybe[nil].or { throw Exception.new("...") } # ==> Exception!

# File lib/monads/maybe.rb, line 160
def or obj = nil, &f
  if obj and f
    f.call obj
  elsif f
    f.call
  else
    obj
  end
end
to_s() click to toggle source
# File lib/monads/maybe.rb, line 180
def to_s
  "None"
end

Protected Instance Methods

_canBind?(name) click to toggle source
# File lib/monads/maybe.rb, line 170
def _canBind? name
  true
end
unwrap() click to toggle source

Unwrap the wrapped value, nil or not

# File lib/monads/maybe.rb, line 150
def unwrap
  nil
end