class Mon::Monad::Final

Final represents a finalized lazy value (i.e. a value with no pending ops).

Public Class Methods

[](obj = nil) click to toggle source

You probably want Lazy

# File lib/monads/lazy.rb, line 71
def self::[](obj = nil)
  Final.new(obj)
end

Protected Class Methods

new(obj) click to toggle source
# File lib/monads/lazy.rb, line 66
def initialize(obj)
  @obj = obj
end

Public Instance Methods

==(o) click to toggle source
# File lib/monads/lazy.rb, line 120
def == o
  eql? o
end
_() click to toggle source

Alias for unwrap

# File lib/monads/lazy.rb, line 99
def _
  unwrap
end
_canBind?(name) click to toggle source
# File lib/monads/lazy.rb, line 85
def _canBind?(name)
  @obj.respond_to? name
end
_finalized?() click to toggle source
# File lib/monads/lazy.rb, line 89
def _finalized?
  true
end
bind(&fun) click to toggle source

Add an operation to be performed on the wrapped value, only if necessary

# File lib/monads/lazy.rb, line 76
def bind(&fun)
  Pending::eventually(fun, [@obj])
end
eql?(o) click to toggle source
# File lib/monads/lazy.rb, line 107
def eql? o
  # Time to collapse
  if o.is_a? Lazy
    self.unwrap == o.unwrap
  else
    self.unwrap == o
  end
end
equals?(o) click to toggle source
# File lib/monads/lazy.rb, line 116
def equals? o
  eql? o
end
finalize() click to toggle source

Perform any pending lazy operations

# File lib/monads/lazy.rb, line 81
def finalize
  self
end
to_s() click to toggle source
# File lib/monads/lazy.rb, line 103
def to_s
  "Final[#{ @obj }]"
end
unwrap() click to toggle source

Perform any pending lazy operations and unwrap the result

# File lib/monads/lazy.rb, line 94
def unwrap
  @obj
end