class Object

Public Instance Methods

filter(&block) click to toggle source
# File lib/ruby-stream.rb, line 121
def filter(&block)
  if block.call(head)
    Stream.new(head) do
      tail.filter(&block)
    end
  else
    tail.filter(&block)
  end
end
fold_left(*args, &block) click to toggle source
# File lib/ruby-stream.rb, line 103
def fold_left(*args, &block)
  zero = args[0]
  symbol = args[1] || args[0]

  scan = if block
    self.scan(zero, &block)
  elsif args.length == 2
    self.scan(zero, &symbol.to_proc)
  elsif args.length == 1
    self.drop(1).scan(head, &symbol.to_proc)
  end

  scan.last
end
Also aliased as: inject, reduce
inject(*args, &block)
Alias for: fold_left
reduce(*args, &block)
Alias for: fold_left
scan(zero, &block) click to toggle source
# File lib/ruby-stream.rb, line 97
def scan(zero, &block)
  Stream.new(zero) do
    tail.scan(block.call(zero, head), &block)
  end
end