class Frappuccino::Stream

Public Class Methods

merge(stream_one, stream_two) click to toggle source
# File lib/frappuccino/stream.rb, line 97
def self.merge(stream_one, stream_two)
  new(stream_one, stream_two)
end
new(*sources) click to toggle source
# File lib/frappuccino/stream.rb, line 28
def initialize(*sources)
  sources.each do |source|
    source.extend(Frappuccino::Source).add_observer(self)
  end
end

Public Instance Methods

collect(hash = nil, &blk)
Alias for: map
count(*args, &blk) click to toggle source
# File lib/frappuccino/stream.rb, line 38
def count(*args, &blk)
  stream = if args.count > 0
    self.select { |value| value == args.first }
  elsif blk
    self.select { |value| blk.call(value) }
  else
    self
  end

  Property.new(0, stream.scan(0) { |last| last + 1 })
end
drop(n) click to toggle source
# File lib/frappuccino/stream.rb, line 65
def drop(n)
  Drop.new(self, n)
end
inject(start, &blk) click to toggle source
# File lib/frappuccino/stream.rb, line 73
def inject(start, &blk)
  Property.new(start, self.scan(start, &blk))
end
map(hash = nil, &blk) click to toggle source
# File lib/frappuccino/stream.rb, line 58
def map(hash = nil, &blk)
  blk = lambda { |event| hash.fetch(event) { hash[:default] } } if hash
  Map.new(self, &blk)
end
Also aliased as: collect, map_stream
map_stream(hash = nil, &blk)
Alias for: map
merge(another_stream) click to toggle source
# File lib/frappuccino/stream.rb, line 93
def merge(another_stream)
  Stream.new(self, another_stream)
end
on_value(&blk) click to toggle source
# File lib/frappuccino/stream.rb, line 89
def on_value(&blk)
  callbacks << blk
end
scan(zero, &blk) click to toggle source
# File lib/frappuccino/stream.rb, line 85
def scan(zero, &blk)
  Scan.new(self, zero, &blk)
end
select(&blk) click to toggle source
# File lib/frappuccino/stream.rb, line 77
def select(&blk)
  Select.new(self, &blk)
end
take(n) click to toggle source
# File lib/frappuccino/stream.rb, line 69
def take(n)
  Take.new(self, n)
end
update(event) click to toggle source
# File lib/frappuccino/stream.rb, line 34
def update(event)
  occur(event)
end
zip(stream) click to toggle source
# File lib/frappuccino/stream.rb, line 81
def zip(stream)
  Zip.new(self, stream)
end

Protected Instance Methods

callbacks() click to toggle source
# File lib/frappuccino/stream.rb, line 112
def callbacks
  @callbacks ||= []
end
occur(value) click to toggle source
# File lib/frappuccino/stream.rb, line 103
def occur(value)
  callbacks.each do |callback|
    callback.call(value)
  end

  changed
  notify_observers(value)
end