Class: Pull::Collect

Inherits:
Object
  • Object
show all
Defined in:
lib/pull/sink/collect.rb

Constant Summary collapse

DEFAULT_DONE_CALLBACK =
-> () {
  puts "DONE"
}

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Collect



9
10
11
12
# File 'lib/pull/sink/collect.rb', line 9

def initialize(&block)
  @block = block
  @collection = []
end

Instance Method Details

#call(read, done = DEFAULT_DONE_CALLBACK) ⇒ Object

Raises:

  • (TypeError)


14
15
16
17
18
19
20
21
# File 'lib/pull/sink/collect.rb', line 14

def call(read, done = DEFAULT_DONE_CALLBACK)
  raise TypeError unless read.respond_to?(:call)
  drained = Pull::Drain.new do |value|
    @collection << value
  end
  drained.(read)
  block.call(@collection)
end