Sha256: 3714026d5e6c5de48b5004e8ed32b38199eca818d0882c0b0ae9222faea79296

Contents?: true

Size: 508 Bytes

Versions: 1

Compression:

Stored size: 508 Bytes

Contents

# frozen_string_literal: true

module Pull
  class Reduce
    DEFAULT_DONE_CALLBACK = -> () {
      puts "DONE"
    }

    def initialize(accumulator, &block)
      @accumulator = accumulator
      @block = block
    end

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

    private

    attr_reader :block
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pull_stream-1.0.0 lib/pull/sink/reduce.rb