function FunctionUtils.memoize(j,f)assert(type(j)=="\102\117\110\099\116\105\111\110")f=f or FunctionUtils.defaultSerializeArgs assert(type(f)=="\102\117\110\099\116\105\111\110")local a={}local m=function(...)local m={...}local X=f(m)if X==nil then return j(...)else if a[X]==nil then a[X]=j(...)end return a[X]end end return m end
--[[
	Cache results of a function such that subsequent calls return the cached result rather than
	call the function again.

	By default, a cached result is stored for each separate combination of serialized input args.
	Optionally memoize takes a serializeArgs function which should return a key that the result
	should be cached with for a given call signature. Return nil to avoid caching the result.
]]
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
