function FunctionUtils.memoize(D,h)assert(type(D)=="\102\117\110\099\116\105\111\110")h=h or FunctionUtils.defaultSerializeArgs assert(type(h)=="\102\117\110\099\116\105\111\110")local M={}local U=function(...)local U={...}local u=h(U)if u==nil then return D(...)else if M[u]==nil then M[u]=D(...)end return M[u]end end return U end

function FunctionUtils.memoize(fn, serializeArgs)
	assert(type(fn) == "function")
	serializeArgs = serializeArgs or FunctionUtils.defaultSerializeArgs
	assert(type(serializeArgs) == "function")
	local cache = {}
	local proxyFunction = function(...)
		local proxyArgs = {...}
		local cacheKey = serializeArgs(proxyArgs)
		if cacheKey == nil then
			return fn(...)
		else
			if cache[cacheKey] == nil then
				cache[cacheKey] = fn(...)
			end
			return cache[cacheKey]
		end
	end
	return proxyFunction
end
