--[=[
	https://rxjs-dev.firebaseapp.com/api/operators/scan

	@param accumulator (current: TSeed, ...: TInput) -> TResult
	@param seed TSeed
	@return (source: Observable<TInput>) -> Observable<TResult>
]=]

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
