Included Modules

Files

LazyList::Enumerable

Public Instance Methods

collect(&f) click to toggle source

Alias for map

combine(other, &operator) click to toggle source

obsoleted by zip

# File lib/lazylist/enumerable.rb, line 57
    def combine(other, &operator)
      warn "method 'combine' is obsolete - use 'zip'"
      zip(other, &operator)
    end
each_with_index(&block) click to toggle source

Calls block with two arguments, the element and its index, for each element of this lazy list. If block isn’t given, the method returns a lazy list that consists of [ element, index ] pairs instead.

# File lib/lazylist/enumerable.rb, line 29
    def each_with_index(&block)
      if block
        each_with_index.each { |x| block[x] }
      else
        i = -1
        map { |x| [ x, i += 1 ] }
      end
    end
filter(&p) click to toggle source

obsoleted by select

# File lib/lazylist/enumerable.rb, line 97
    def filter(&p)
      warn "method 'filter' is obsolete - use 'select'"
      select(&p)
    end
find_all(&block) click to toggle source

Alias for select

grep(pattern, &block) click to toggle source

Returns a lazy list every element of this lazy list for which pattern === element is true. If the optional block is supplied, each matching element is passed to it, and the block’s result becomes an element of the returned lazy list.

# File lib/lazylist/enumerable.rb, line 66
    def grep(pattern, &block)
      result = select { |x| pattern === x }
      block and result = result.map(&block)
      result
    end
map(&f) click to toggle source

Creates a new Lazylist that maps the block or Proc object f to every element in the old list.

# File lib/lazylist/enumerable.rb, line 104
    def map(&f)
      return empty if empty?
      f = Identity unless f
      self.class.new(delay { f[head] }) { tail.map(&f) }
    end
Also aliased as: collect
mapper(&f) click to toggle source

obsoleted by map

# File lib/lazylist/enumerable.rb, line 112
    def mapper(&f)
      warn "method 'mapper' is obsolete - use 'map'"
      map(&f)
    end
partition(&block) click to toggle source

Returns two lazy lists, the first containing the elements of this lazy list for which the block evaluates to true, the second containing the rest.

# File lib/lazylist/enumerable.rb, line 8
    def partition(&block)
      return select(&block), reject(&block)
    end
reject() click to toggle source

Returns a lazy list of all elements of this lazy list for which the block is false (see also +Lazylist#select+).

# File lib/lazylist/enumerable.rb, line 74
    def reject
      select { |obj| !yield(obj) }
    end
select(&block) click to toggle source

Returns a lazy list of all elements of this lazy list for which block is true.

# File lib/lazylist/enumerable.rb, line 80
    def select(&block)
      block = All unless block
      s = self
      ended = catch(:end_list) do
        until s.empty? or block[s.head]
          s = s.tail
        end
      end
      if s.empty? or ended == :end_list
        empty
      else
        self.class.new(delay { s.head }) { s.tail.select(&block) }
      end
    end
Also aliased as: find_all
sort() click to toggle source

Returns a sorted version of this lazy list. This method should only be called on finite lazy lists or it will never return. Also see Enumerable#sort.

# File lib/lazylist/enumerable.rb, line 15
    def sort # :yields: a, b
      LazyList.from_enum(super)
    end
sort_by() click to toggle source

Returns a sorted version of this lazy list. This method should only be called on finite lazy lists or it will never return. Also see Enumerable#sort_by.

# File lib/lazylist/enumerable.rb, line 22
    def sort_by # :yields: obj
      LazyList.from_enum(super)
    end
zip(*others, &block) click to toggle source

Returns the lazy list, that contains all the given block’s return values, if it was called on every

 self[i], others[0][i], others[1][i],... others[others.size - 1][i]

for i in 0..Infinity. If block wasn’t given this result will be the array

 [self[i], others[0][i], others[1][i],... ]

and a lazy list of those arrays is returned.

# File lib/lazylist/enumerable.rb, line 45
    def zip(*others, &block)
      if empty? or others.any? { |o| o.empty? }
        empty
      else
        block ||= Tuple
        self.class.new(delay { block[head, *others.map { |o| o.head }] }) do
          tail.zip(*others.map { |o| o.tail }, &block)
        end
      end
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.