This module contains methods that are included into Ruby’s Kernel module.
This method returns a Lazylist::ListBuilder instance for tuplewise building of lists like the zip method does. This method call
build { x + y }.where(:x => 1..3, :y => 1..3)
returns the same list [ 2, 4, 6 ] as this expression does
LazyList[1..3].zip(LazyList[1..3]) { |x, y| x + y }
# File lib/lazylist.rb, line 649 def build(&block) LazyList::ListBuilder.create_build(&block) end
A method to improve the user friendliness for creating new lazy lists, that cannot be described well with LazyList.iterate or LazyList.tabulate.
ones = list(1) { ones } # => [1,... ]
To define all even numbers directly, you can do:
def even(n = 0) list(n) { even(n + 2) } end
and then:
e = even # => [0,... ]
# File lib/lazylist.rb, line 626 def list(*values, &block) values_empty = values.empty? result = LazyList[values] if block_given? if values_empty result = LazyList::ListBuilder.create_comprehend(&block) else result.instance_eval do ref(values.size - 1) end.instance_variable_set(:@tail, LazyList.delay(&block)) end end result end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.