function Rx.scan(d,M)assert(type(d)=="\102\117\110\099\116\105\111\110","\066\097\100 \097\099\099\117\109\117\108\097\116\111\114")return function(b)assert(Observable.isObservable(b),"\066\097\100 \111\098\115\101\114\118\097\098\108\101")return Observable.new(function(f)local t=M return b:Subscribe(function(...)t=d(t,...)f:Fire(t)end,f:GetFailComplete())end)end end

function Rx.scan(accumulator, seed)
	assert(type(accumulator) == "function", "Bad accumulator")

	return function(source)
		assert(Observable.isObservable(source), "Bad observable")

		return Observable.new(function(sub)
			local current = seed

			return source:Subscribe(function(...)
				current = accumulator(current, ...)
				sub:Fire(current)
			end, sub:GetFailComplete())
		end)
	end
end
