function FunctionUtils.debounce(F,x)assert(FunctionUtils.isCallable(F))assert(type(x)=="\110\117\109\098\101\114")local k=0 local A=nil return function(...)local R={...}k=k+1 local v=k delay(x,function()if v~=k then return end A=F(unpack(R))end)return A end end

function FunctionUtils.debounce(fn, secondsDelay)
	assert(FunctionUtils.isCallable(fn))
	assert(type(secondsDelay) == "number")

	local lastInvocation = 0
	local lastResult = nil

	return function(...)
		local args = {...}

		lastInvocation = lastInvocation + 1

		local thisInvocation = lastInvocation
		delay(
			secondsDelay,
			function()
				if thisInvocation ~= lastInvocation then
					return
				end

				lastResult = fn(unpack(args))
			end
		)

		return lastResult
	end
end
