Class: Functional::Reduce

Inherits:
Base show all
Defined in:
lib/functional.rb

Instance Attribute Summary

Attributes inherited from Base

#exe, #next

Instance Method Summary collapse

Methods inherited from Base

#to_proc

Constructor Details

#initialize(iv, *a, &e) ⇒ Reduce

Returns a new instance of Reduce.



158
159
160
161
162
# File 'lib/functional.rb', line 158

def initialize iv, *a, &e
	super *a, &e
	@buf = {}
	@buf.default = iv
end

Instance Method Details

#call(*a) ⇒ Object



164
165
166
# File 'lib/functional.rb', line 164

def call *a
	@buf[ a[0]] = @exe.call @buf[ a[0]], *a[1..-1]
end

#endObject



168
169
170
171
# File 'lib/functional.rb', line 168

def end
	@buf.each {|i| @next.call *i}
	@next.end
end