class Lab42::Stream

Constants

ConstraintError
EmptyStream
IllegalState
Version

Attributes

first[R]
head[R]
promise[R]

Private Class Methods

new(h, t=nil, &tail) click to toggle source
# File lib/lab42/stream.rb, line 61
def initialize h, t=nil, &tail
  @head    = h
  @promise = ( t || tail ).memoized
end

Private Instance Methods

+(other)
Alias for: append
__combine_streams__(op, args) click to toggle source
# File lib/lab42/stream.rb, line 53
def __combine_streams__ op, args
  return empty_stream if args.any?(&:empty?)

  new_head = op.(head, *args.map(&:head))
  cons_stream( new_head ){ tail.__combine_streams__(op, args.map(&:tail)) }
end
append(other) click to toggle source
# File lib/lab42/stream.rb, line 22
def append other
  raise ArgumentError, "not a stream #{other}" unless self.class === other
  cons_stream( head ){ tail.append other }
end
Also aliased as: +
combine_streams(*args, &operation) click to toggle source
# File lib/lab42/stream.rb, line 29
def combine_streams *args, &operation
  op = args.shift unless self.class === args.first
  raise ArgumentError, "Missing stream parameters" if args.empty?
  __combine_streams__ Behavior.make( op, &operation), args
end
drop(n = 1) click to toggle source
# File lib/lab42/stream.rb, line 35
def drop n = 1
  raise ArgumentError, "not a non negative number" if n < 0
  t = self
  loop do
    return t if n.zero?
    n -=1
    t = t.tail
  end
end
empty?() click to toggle source
# File lib/lab42/stream.rb, line 45
def empty?; false end
tail() click to toggle source
# File lib/lab42/stream.rb, line 47
def tail
  promise.()
end
to_stream() click to toggle source
# File lib/lab42/stream.rb, line 51
def to_stream; self end