public
Description: Simple and non-magical lazy evaluation mechanism for Ruby
Homepage:
Clone URL: git://github.com/mmcgrana/simple_promise.git
name age message
file LICENSE Loading commit data...
file README.textile
directory lib/
file simple_promise.gemspec
directory spec/
README.textile

A lazy evaluation implementation:

lazy = SimplePromise.new { 1 + 1 } lazy + 3
  1. 5
lazy = SimplePromise.new { puts “executing”; 1 + 1 } lazy + 3 (prints “executing”)
  1. 5

A SimplePromise differs from the result of its promised block only in two ways.
First, #inspect shows that it is in fact a promise:

lazy = SimplePromise.new { 1 + 1 } lazy.inspect
  1. #<SimplePromise computation=#<Proc:0×000@/foo.rb:44> result=[promised]>
lazy + 3 lazy.inspect
  1. #<SimplePromise computation=#<Proc:0×000@/foo.rb:44> result=2>

Second, literal truthiness evaluations will always be positive:

lazy_true = SimplePromise.new { true } lazy_false = SimplePromise.new { false } lazy_true ? “positve truthiness” : “negative truthiness”
  1. “positive truthiness”
lazy_false ? “positve truthiness” : “negative truthiness”
  1. “positve truthiness”